/*根據(jù)學號修改信息*/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();}執(zhí)行類: 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條經(jīng)驗 獲得超25個贊
再加上一行 ptmt.setInt(9,s.getSno());
如果是主鍵那么 去掉ptmt.setInt(1,s.getSno());
如果正確請采納
添加回答
舉報
0/150
提交
取消