wood burning stoves 2.0*
The moose likes JDBC and the fly likes Can't execute prepared statements using mySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can Watch "Can New topic

Can't execute prepared statements using mySQL

JoseAntonio Quiles

Joined: Jun 07, 2002
Posts: 5
I am using mySQL 4.01 and mm JDBC driver 3.05
String query = "select * from test_table where b = ?";
PreparedStatement Stmt = Conn.prepareStatement(query);
I get the following exception:
java.sql.SQLException: Syntax error or access violation, message from server: "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"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1613)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:880)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:939)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:911)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1777)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1711)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1203)
If I don't use prepared statement, it works.
Any ideas?
thank you in advance.
Jon Strayer
Ranch Hand

Joined: Dec 04, 2002
Posts: 133
[ February 11, 2003: Message edited by: Jon Strayer ]

JoseAntonio Quiles

Joined: Jun 07, 2002
Posts: 5
That was the problem.
Thank you very much.
I agree. Here's the link: http://aspose.com/file-tools
subject: Can't execute prepared statements using mySQL
Similar Threads
Configuring the Datasource forJBOSS
mysql- problem with prepared statemnt
Stored procedure cannot be imported from java...?
submitting the applet input details to database
Batch Delete Problem