0
public static Boolean userImage(String userIdString, InputStream stream) {

        PreparedStatement statement = null;    
        String updateTableSQL = "UPDATE `users` SET `image` = ? WHERE `id` = ? ;";

        try {

            Integer userId = Integer.parseInt(userIdString);    
            statement = DatabaseManager.getConnection().prepareStatement(updateTableSQL);    
            statement.setBinaryStream(1, stream);
            statement.setInt(2, userId);                
            Log.write("USER IMAGE UPDATED> " + statement);              
            statement.executeUpdate(updateTableSQL);                

            return true;

        } catch (Exception e) {

            Log.write("USER IMAGE UPDATED> " + e.getMessage());    
            return false;

        } finally {

            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }

    }

Log:

09:55:59:0496: USER IMAGE UPDATED> com.mysql.jdbc.JDBC42PreparedStatement@1c902d70: UPDATE users SET image = ** STREAM DATA ** WHERE id = 29 ;

09:55:59:0511: USER IMAGE UPDATED> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? WHERE id = 29' at line 1

0

1 Answer 1

1

You are using the wrong version of executeUpdate

As you have already created a statement with parameters

change statement.executeUpdate(updateTableSQL); to statement.executeUpdate();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.