一张表 表名mission
number describe 两个字段
以下是修改用到的两处代码
public boolean upd(String sql, String parameters[])
throws ClassNotFoundException, SQLException {
boolean flag=false;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/users", "root", "070902");
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
for(int i=0;i<parameters.length;i++){
ps.setString(i+1, parameters[i]);
}
int rs = ps.executeUpdate();
if(rs==1) flag=true;
return flag;
}
//修改任务
public boolean updMission(Mission mission){
boolean b=false;
String sql="update mission set describe=? where id=?";
String parameters[] ={mission.getDescribe(),mission.getNumber()+""};
SqlHelper sp = new SqlHelper();
try {
b =sp.upd(sql, parameters);
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
}
return b;
}
mission是个对象 构造应该没问题 编译通过 运行报错
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 'describe='w' where number='10'' at line 1
我在另外一个地方一模一样的方法 可以修改成功 就是where 后面的条件
求大神帮忙看下了 刚学 找错好久了