/*根据学号修改信息*/public void updateStudent(Student s)throws SQLException{ Connection conn=DB1.getConnection(); String sql="" + " update student " + " set sno=?,sname=?, sdept=?, sclass=?, sphone=?, smajor=?, sdormno=?, sdorm=? " + " where sno=? "; PreparedStatement ptmt=conn.prepareStatement(sql); ptmt.setInt(1,s.getSno()); ptmt.setString(2, s.getSname()); ptmt.setString(3,s.getSdept()); ptmt.setString(4,s.getSclass()); ptmt.setInt(5,s.getSphone()); ptmt.setString(6, s.getSmajor()); ptmt.setString(7,s.getSdormno()); ptmt.setInt(8,s.getSdorm()); ptmt.execute();}执行类: StudentDao s=new StudentDao(); Student s1=new Student(); s1.setSno(1); s1.setSname("大仙"); s1.setSdept("土木学院"); s1.setSclass("计3"); s1.setSphone(182556); s1.setSmajor("土木工程"); s1.setSdormno("c18"); s1.setSdorm(119); s.updateStudent(s1); 下面报错,找半天都解决不了问题,运行不了Exception in thread "main" java.sql.SQLException: Statement parameter 1 not set. at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:992) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:770) at dao.StudentDao.updateStudent(StudentDao.java:48) at action.StudentAction.main(StudentAction.java:21)
1 回答
已采纳
Corbie亚东
TA贡献53条经验 获得超25个赞
再加上一行 ptmt.setInt(9,s.getSno());
如果是主键那么 去掉ptmt.setInt(1,s.getSno());
如果正确请采纳
添加回答
举报
0/150
提交
取消