PreparedStatement setString issue
Posted by:
miro s.
Date: March 16, 2012 03:09AM
Hi, we are facing to the problem with PreparedStatement with MySql jdbc driver.
Here is code:
PreparedStatement stmt = conn.prepareStatement("select * from ?");
stmt.setString(1, "test");
ResultSet rs = stmt.executeQuery();
But exception is thrown:
com.mysql.jdbc.exceptions.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 ''test'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1262)
at test.MySqlTest.main(MySqlTest.java:34)
So it seems that table cannot be set as parameter in PreparedStatement?
Has anyone else same problem?
thanks
miro
Subject
Written By
Posted
PreparedStatement setString issue
March 16, 2012 03:09AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.