一、报错!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 '? , end=? WHERE pointno=? AND component=?' at line 1
错误情况:
错误出现在如下关键代码中:
String sql = "UPDATE db_xiaowan.config SET start=? , end=? WHERE pointno=? AND component=?";
statement = connection.prepareStatement(sql);
statement.setString(1, startdate);
statement.setString(2, enddate);
statement.setString(3, pointno);
statement.setString(4, component);
int row=statement.executeUpdate(sql);
if(row!=0)
flag = true
然后报错这个: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 '? , end=? WHERE pointno=? AND component=?' at line 1
寻错过程:
百度了一下错误,说一般报这种错误,都是sql语句写错了。于是我改了好久的sql语句,但是发现在navicat管理工具中sql语句执行成功了,结果发现不是sql语句的问题。
解决方法:
最后经过逐行排查发现问题出在这一句:int row=statement.executeUpdate(sql);
excuteUpdate()括号中不该有参数。。。应该改为int row=statement.executeUpdate();
又是小问题,不够细心!!谨以此文告诫自己!如能帮上其他类似错误的朋友也不胜荣幸!