在JDBC的使用里,我的数据需要更新,确不成功
public static void changeOtherAccount() {
ResultSet rs;
PreparedStatement preSql;
Connection con3=new DBconn().getConn();
String sql="update user set name=?,password=? where account=?";
try {
String account=ChangeAccountMessage.accounttext.getText();
String name=ChangeAccountMessage.nametext.getText();
String password=new String(ChangeAccountMessage.passwordtext.getPassword());
preSql=con3.prepareStatement(sql);
preSql.setString(1,name);
preSql.setString(2,password);
preSql.setString(3,account);
boolean ok=preSql.execute(sql);
System.out.println(ok);
} catch (SQLException e) {
System.out.println(e);
}
}
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 '?,password=? where account=?' at line 1
暂时没有
数据更新成功
没用过你这个mysql写法.但是看SQL语句的那个?号值是没赋上.preSql是设置值.然后preSql.excuteUpdate(Sql),这里是不是不对劲
现在的报错语句是这样的
看报错信息是语法错误,检查下name,password,account是不是没有值。还有可以试试把name,password,account三个代入上面的sql中,自己执行下
near '?,password=? where account=?' at line 1 你查询语句是这样写的,正确的是 用and
眼熟不?