首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

PreparedStatement施用注意

2013-01-04 
PreparedStatement使用注意String sql SELECT value from user where + ` + idField + ` + ?s

PreparedStatement使用注意

String sql = "SELECT value from user where" + "`" + idField + "`" + "=?";st = (PreparedStatement) connection.prepareStatement(sql);st.setString(1, "0001");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()

热点排行