Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Updates user
- * @param user
- * @throws SQLException
- */
- public void updateUser(User user) throws SQLException {
- String updateQuery = "UPDATE users SET user_id = ?, name = ?"
- + "WHERE user_id = ?";
- connect();
- PreparedStatement preparedStatement = connection.prepareStatement(updateQuery);
- preparedStatement.setInt(1,user.getId());
- preparedStatement.setString(2,user.getName());
- preparedStatement.execute();
- preparedStatement.close();
- disconnect();
- }
- public static void main(String args[]) throws SQLException {
- UserAccesser userAccesser = new UserAccesser("root","jdbc:mysql://localhost:3306/userdb" +
- "?verifyServerCertificate=false"+
- "&useSSL=false"+
- "&requireSSL=false"+
- "&useLegacyDatetimeCode=false"+
- "&"+
- "&serverTimezone=UTC","powerlum925");
- userAccesser.connect();
- userAccesser.updateUser(new User(65,"testUser65"));
- }
- Exception in thread "main" java.sql.SQLException: No value specified for parameter 3
- at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
- at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
- at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
- at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:414)
- at com.cheerbuilder.dbAccess.UserAccesser.updateUser(UserAccesser.java:165)
- at com.cheerbuilder.dbAccess.UserAccesser.main(UserAccesser.java:205)
Add Comment
Please, Sign In to add comment