PreparedStatement使用注意

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() 
posted on 2013-02-19 20:57  蜜雪薇琪  阅读(244)  评论(0编辑  收藏  举报