This week's book giveaway is in the Android forum.
We're giving away four copies of Android Programming: The Big Nerd Ranch Guide and have Bill Phillips & Chris Stewart on-line!
See this thread for details.
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't execute prepared statements using mySQL  RSS feed

 
JoseAntonio Quiles
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
Stmt.setString(1,s);
Stmt.executeQuery(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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
Stmt.executeQuery();
[ February 11, 2003: Message edited by: Jon Strayer ]
 
JoseAntonio Quiles
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was the problem.
Thank you very much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!