当前位置: 代码迷 >> Java Web开发 >> PreparedStatement中update语句更新有关问题
  详细解决方案

PreparedStatement中update语句更新有关问题

热度:10151   发布时间:2013-02-25 21:15:58.0
PreparedStatement中update语句更新问题。
代码如下:
PreparedStatement pstm = null;
String sql = null;
MysqlConnection mc = new MysqlConnection();
sql = "update employee set Password = ? where UserName = ?";
try{
pstm= mc.getConnection().prepareStatement(sql);
pstm.setString(1, cd.getCpwd());
pstm.setString(2,cd.getUsername());
pstm.executeUpdate(sql);

}catch (Exception e) {

e.printStackTrace();
}


sql = "update employee set Password = ? where UserName = ?";中Password=?这样写是否正确。


抛出的异常如下:

 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 '? where UserName = ?' at line 1


------解决方案--------------------------------------------------------
你有一个错误在您的SQL语法;检查手册,对应于您的MySQL服务器版本正确的语法使用在吗?这里用户名= ?”在第1行

总不能是连接未关闭导致的吧~~
------解决方案--------------------------------------------------------
错误的sql语法

你写的sql语句确实没错,你看看传的参数是不是正确的,比如说cd.getCpwd()出现null什么的
------解决方案--------------------------------------------------------
先拼接一下SQL 然后看看SQL是什么 在数据库中执行一下看有没有问题。。
  相关解决方案