In general, the problem is that with SQL request for update, the generated keys are not returned, although the record is updated, everything works correctly with insert, but everything breaks with update, someone has encountered such a problem.
UPDATE method rs.next () always returns false
int user_id = 0; ResultSet rs = null; try { dbConnection = getDBConnection(); preparedStatement = dbConnection.prepareStatement(User.UPDATE_USER, new String[]{User.ID}); preparedStatement.setString(1, password); preparedStatement.setString(2, username); preparedStatement.executeUpdate(); rs = preparedStatement.getGeneratedKeys(); if (rs.next()) { user_id = rs.getInt(1); } } finally { if (rs != null) rs.close(); preparedStatement.close(); dbConnection.close(); }
Sql code itself
static final String UPDATE_USER = "UPDATE " + TABLE_NAME + " SET " + PASSWORD + " = ?" + " WHERE "+ USERNAME +" = ?;";