executeQuery

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

executeQuery

Postby Democre » 08 Jan 2011, 03:10

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.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Jan 2011, 17:16

Tested and found a bug.
Thanks for reporting. It will be fixed with the next release. Sorry for the inconvenience.
Lapo
--
gotoAndPlay()
...addicted to flash games
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 20 Mar 2011, 15:28

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
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 20 Mar 2011, 16:22

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);
        }
    };
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 21 Mar 2011, 09:41

Interesting. Can you show an example of how you use it?
Lapo

--

gotoAndPlay()

...addicted to flash games
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 21 Mar 2011, 09:52

how i use executeUpdate or apache dbutils?
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 08 Apr 2011, 18:44

executeUpdate(String, Object[]) is still broken in RC2a. It gives the same errors as above.
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 11 Apr 2011, 10:46

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.
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 11 Apr 2011, 22:53

I too use an alternative (Groovy) but just thought they'd like to know that their method is still borked.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 52 guests