gpt4 book ai didi

java - 在 Java 中更新 blob

转载 作者:行者123 更新时间:2023-11-30 23:47:10 25 4
gpt4 key购买 nike

当我想更新表中的 blob 列时出现此错误

Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.

但我的陈述是可以更新的!有谁能够帮助我 ?

这是我创建语句的代码

public PreparedStatement getPreparedStatement(String sql) {
try {
return con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
} catch (SQLException ex) {
Logger.getLogger(DatabaseAccessor.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}

这就是我想要更新 blob 的方式

resultSet.updateBlob("mainPic", mainPic.getInputStream());

最佳答案

这是我的代码:

DatabaseAccessor accessor = new DatabaseAccessor();
PreparedStatement statement = accessor.getPreparedStatement("SELECT * FROM mainpage WHERE ID=0");
ResultSet resultSet = statement.executeQuery();
resultSet.next();

mainPic = request.getPart("mainPic");
resultSet.updateBlob("mainPic", mainPic.getInputStream());

关于java - 在 Java 中更新 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32314138/

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