gpt4 book ai didi

java - 从 java 更新 Blob 时出现 SQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 10:44:45 25 4
gpt4 key购买 nike

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();
}
}

}

}

日志:

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

最佳答案

您使用的 executeUpdate 版本错误

因为您已经创建了带参数的语句

statement.executeUpdate(updateTableSQL);更改为statement.executeUpdate();

关于java - 从 java 更新 Blob 时出现 SQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com