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

标签 java mysql

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/

相关文章:

派生表上的 mysql 求和比没有它的求和更快

java - 无法使用 Jasper 报告库生成 Excel 工作表报告

java - 数据太大,无法进行 int 索引

java - 远程使用 document4j 将 DOCX 转换为 PDF java

mysql 5.7 geospatial 用于地理位置距离查询

php - 从表格行填充表单

java - 如何绑定(bind)到 Cloud Spanner Java API 中的 IN 参数

java - 需要将一个对象转换为无限通配符....但在我的情况下如何?

php - 如何在同一个表中使用php比较两列的值,如果值相同则为它们着色

php - Symfony2 与学说 : Nested conditions for findBy