zPr*_*mer 0 java mysql jdbc prepared-statement
对于准备好的语句,我在语法方面遇到了一些麻烦.
我有以下代码
String query2="SELECT lname FROM school_student WHERE sid = ? ORDER BY sid;";
PreparedStatement ps = cn.prepareStatement(query2);
ps.setInt(1, 3);
ResultSet rs = ps.executeQuery(query2);
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我收到此错误消息:
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 '? ORDER BY sid' at line 1
但是,当我替换"?" 在我的查询3中,查询工作正常,没有错误,并给我我想要的.我如何设置"?"的值似乎有问题.在我的查询?我使用了错误的语法吗?
简单地使用
ps.executeQuery();
Run Code Online (Sandbox Code Playgroud)
(即使用executeQuery()不带任何参数的重载方法).您在准备语句时已经传递了查询.
| 归档时间: |
|
| 查看次数: |
324 次 |
| 最近记录: |