java - Java:如何将 JSON 对象插入到 CLOB 到 oracle 数据库中
问题描述
我有一个org.json.simple.JSONObject
并且我想使用 PreparedStatement 将它插入到 Oracle 数据库中的 clob 类型列中。我怎样才能做到这一点?
当我这样做时,preparedStatement.setObject(1, json_obj);
我收到错误:无法在 setObject 中推断 org.json.simple.JSONObject 的 SQL 类型
解决方案
我将 json 作为字符串并创建了这个方法,它对我有用:
public long insertClob(String id, String json ) {
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement("UPDATE tableWithClobColumn SET clobColumn=? WHERE id=?",
Statement.RETURN_GENERATED_KEYS);
Reader reader = new StringReader(json);
ps.setClob(1, reader);
ps.setString(2, "1911030604");
return ps;
}
}, holder);
return Long.parseLong("0");
}
推荐阅读
- python - 为什么即使 a 是整数,a== type(int) 后面的代码也不会打印?
- javascript - RabbitMQ:通过设置“src-exchange”和“src-exchange-key”参数使用动态铲子插件在队列之间移动消息
- scala - 在匹配情况下使用模式绑定器进行类型推断无法按预期工作
- c# - 当前上下文中不存在名称“InitializeComponent”
- flutter - 颤振文本表单字段。如何在 TextFormField 中粘贴验证文本
- r - 在基本 r 图中为非线性 x 轴值制作等距刻度线
- c - 如何创建一个带有指向 C 中另一个链接的指针的列表?
- javascript - 读出 textarea 的值时,我没有得到 \n 字符
- canoe - vteststudio 的 .vtuexe 文件可以在不是 CANOE 的东西上执行吗?
- php - google api 日历集成无法识别上午/下午