Guest User

Untitled

a guest
Aug 26th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. /**
  2. * Updates user
  3. * @param user
  4. * @throws SQLException
  5. */
  6. public void updateUser(User user) throws SQLException {
  7.  
  8. String updateQuery = "UPDATE users SET user_id = ?, name = ?"
  9. + "WHERE user_id = ?";
  10.  
  11. connect();
  12.  
  13. PreparedStatement preparedStatement = connection.prepareStatement(updateQuery);
  14.  
  15. preparedStatement.setInt(1,user.getId());
  16.  
  17. preparedStatement.setString(2,user.getName());
  18.  
  19. preparedStatement.execute();
  20.  
  21. preparedStatement.close();
  22.  
  23. disconnect();
  24. }
  25.  
  26.  
  27. public static void main(String args[]) throws SQLException {
  28.  
  29. UserAccesser userAccesser = new UserAccesser("root","jdbc:mysql://localhost:3306/userdb" +
  30. "?verifyServerCertificate=false"+
  31. "&useSSL=false"+
  32. "&requireSSL=false"+
  33. "&useLegacyDatetimeCode=false"+
  34. "&amp"+
  35. "&serverTimezone=UTC","powerlum925");
  36.  
  37. userAccesser.connect();
  38.  
  39. userAccesser.updateUser(new User(65,"testUser65"));
  40.  
  41.  
  42.  
  43. }
  44.  
  45. Exception in thread "main" java.sql.SQLException: No value specified for parameter 3
  46. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
  47. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
  48. at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
  49. at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:414)
  50. at com.cheerbuilder.dbAccess.UserAccesser.updateUser(UserAccesser.java:165)
  51. at com.cheerbuilder.dbAccess.UserAccesser.main(UserAccesser.java:205)
Add Comment
Please, Sign In to add comment