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
usersSETimage= ** STREAM DATA ** WHEREid= 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