"SELECT * FROM products WHERE product_name = ?";
This is the error message i am getting
String sql = "SELECT * FROM posdb.products WHERE products.product_name = ?";
PreparedStatement ps = myCon.CreateConnection().prepareStatement(sql);
这是我收到的错误消息:
You have an error in your sql statement, check the manual that
corresponds to your MariaDB server version for the right
syntax to use near '?' at line 1
答案 0 :(得分:0)
使用PreparedStatement
时,您需要替换每个“?”在执行实际查询之前输入有效值。
所以代码的基础是:
String sql = "Select * from SomeTable where SomeColumn = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, someColumnVariable);
ResultSet rs = stmt.executeQuery();