最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
clob字段的处理(oracle)
时间:2022-07-02 18:16:30 编辑:袖梨 来源:一聚教程网
先用PrepareStatement 对象插入(
这时一定要设定Connection对象的AutoCommit为false,即
conn.setAutoCommit(false);
),语句这样写:
String sql = "INSERT INTO flower_news (flower_news_id,news_content,news_author) VALUES (flower_news_id_s.nextval,empty_clob(),?)";
这里news_content字段为clob值。
然后再用select news_content from folwer_news where ....取出刚才插入的那条记录。
再看下面的代码:
rs = st.executeQuery(sql);
java.sql.Clob clob ;
if (rs.next()) {
clob = ((OracleResultSet)rs).getClob(1);
oracle.sql.CLOB my_clob = (oracle.sql.CLOB)clob;
OutputStream writer = my_clob.getAsciiOutputStream();
byte[] contentStr = this.getContent().getBytes();
writer.write(contentStr);
writer.flush();
writer.close();
}
conn.commit();//到最后才提交
其中这个方法我是取到要插入的字符串
你看看吧,照这样做是没有问题的
在整个过程中你都不能提交,否则是不会成功的
这时一定要设定Connection对象的AutoCommit为false,即
conn.setAutoCommit(false);
),语句这样写:
String sql = "INSERT INTO flower_news (flower_news_id,news_content,news_author) VALUES (flower_news_id_s.nextval,empty_clob(),?)";
这里news_content字段为clob值。
然后再用select news_content from folwer_news where ....取出刚才插入的那条记录。
再看下面的代码:
rs = st.executeQuery(sql);
java.sql.Clob clob ;
if (rs.next()) {
clob = ((OracleResultSet)rs).getClob(1);
oracle.sql.CLOB my_clob = (oracle.sql.CLOB)clob;
OutputStream writer = my_clob.getAsciiOutputStream();
byte[] contentStr = this.getContent().getBytes();
writer.write(contentStr);
writer.flush();
writer.close();
}
conn.commit();//到最后才提交
其中这个方法我是取到要插入的字符串
你看看吧,照这样做是没有问题的
在整个过程中你都不能提交,否则是不会成功的
相关文章
- 红色的炼金术士店铺自动上货技巧 11-05
- 绝对魔权第三张图口令任务完成方法 11-05
- 洛克王国世界家园舒适度怎么提升-家园舒适度提升攻略 11-05
- 逃离鸭科夫stg77获取位置介绍说明 11-05
- 绯红编年史挑战模式赤红潜行者攻略 11-05
- 红色的炼金术士店铺售卖物品推荐 11-05