/*根据学号修改信息*/
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)
Corbie亚东
相关分类