利用PreparedStatement执行插入,更新的操作时候:
如:
PreparedStatement pstmt=....
String update = "update mytable set studentId=?,politics=?,minzu=?,dormAddress=?,dormPhone=?,email=?,
phoneNumber=?,homeAddress=?,post=?,homePhone=?,from=?,others=? where name=?";
pstmt.setString(1,name);
...;
出现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 'from='from', others=null where name= "ok"'
当我去掉update语句后面的from=?,others=?时候,此时能够正常执行更新操作,这是什么原因呢?
我用的mysql的版本是5.5
from是mysql中的关键字,是不允许使用的,改个名字
[url]http://zhouhaitao.iteye.com/blog/859932[/url] 看看这篇博客吧 对你有帮助
如果非要使用这样的词,可以这样做 [from] 这样就可以避免与关键字冲突了。