PreparedStatement使用注意

来源:互联网 发布:积分商城数据分析 编辑:程序博客网 时间:2024/06/11 01:18
Java代码 复制代码 收藏代码
  1. String sql = "SELECT value from user where" + "`" + idField + "`" + "=?";
  2. st = (PreparedStatement) connection.prepareStatement(sql);
  3. st.setString(1, "0001");
  4. rs = st.executeQuery(sql);//此处会报错!


mysql报错如下:
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

解决办法:
将rs = st.executeQuery(sql)改为rs = st.executeQuery() 
原创粉丝点击