Page 1 of 1

executeQuery

Posted: 08 Jan 2011, 03:10
by Democre
Hello,
I have a problem.
I was using a prepared statement before, and tried switch over to use this

Code: Select all

        String sql = "SELECT * FROM users WHERE username=?";
        ISFSArray result = db.executeQuery(sql, new Object[]{name});

This now gives me the following error:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1


It worked fine with prepared statements, and now fails. I'm using MySQL.
I'll go back to getConnection and preparing statements I guess.

Posted: 09 Jan 2011, 17:16
by Lapo
Tested and found a bug.
Thanks for reporting. It will be fixed with the next release. Sorry for the inconvenience.

Posted: 20 Mar 2011, 15:28
by dingo
executeQuery seems to work now with RC2, but executeUpdate still seems to throw an error. Am I doing something wrong here?

Code: Select all

String sql = "UPDATE inviteCodes SET numTimesUsed=50 WHERE id=?";
dbManager.executeUpdate(sql, new Object[]{1});


error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

Posted: 20 Mar 2011, 16:22
by dingo
by the way, I just tried out apache dbutils, work great so far:
http://commons.apache.org/dbutils/

you can use the following handler to convert the ResultSet to an SFSArray:

Code: Select all

ResultSetHandler<ISFSArray> h = new ResultSetHandler<ISFSArray>()
    {
        public ISFSArray handle(ResultSet rs) throws SQLException
        {
            return SFSArray.newFromResultSet(rs);
        }
    };

Posted: 21 Mar 2011, 09:41
by Lapo
Interesting. Can you show an example of how you use it?

Posted: 21 Mar 2011, 09:52
by dingo
how i use executeUpdate or apache dbutils?

Posted: 08 Apr 2011, 18:44
by Democre
executeUpdate(String, Object[]) is still broken in RC2a. It gives the same errors as above.

Posted: 11 Apr 2011, 10:46
by dingo
yes, i switched everything to apache queryrunner for simple queries/updates.
it's very easy to use:
http://commons.apache.org/dbutils/examples.html

when i have to retrieve the generated keys i use PreparedStatement directly.

Posted: 11 Apr 2011, 22:53
by Democre
I too use an alternative (Groovy) but just thought they'd like to know that their method is still borked.