+ -
当前位置:首页 → 问答吧 → executeUpdate(sql)这条语句为啥总不执行呢?求教

executeUpdate(sql)这条语句为啥总不执行呢?求教

时间:2011-10-19

来源:互联网

我的代码:
  String sql = "UPDATE ACCOUNTS SET 密码=" + account.getPassword()
+ " WHERE 账户名=" + account.getAccountName();

try {
Class.forName(this.dbDriver).newInstance();
} catch (Exception e) {
e.printStackTrace();
}

try {
Connection conn = DriverManager.getConnection(this.dbUrl,
this.user, this.password);
if (!conn.isClosed()) {
Statement st = conn.createStatement();
Account acc = this.getAccountInfo(account.getAccountName());
if (acc != null) {
System.out.println(2);
int count = st.executeUpdate(sql);
System.out
.println(count
+ " account's information has been updated in table ACCOUNTS!");
} else
System.out
.println("There isn't the account which you want to update its information!");
}
} catch (SQLException e) {

}

作者: Kobe8Bryant24   发布时间: 2011-10-19

这样试试
 String sql = "UPDATE ACCOUNTS SET 密码='" + account.getPassword()
+ "' WHERE 账户名='" + account.getAccountName()+"'";
注意要加''

作者: keiy   发布时间: 2011-10-19