oracle java 插入 clob insert clob hibernate

本文介绍了一种将大型字符串转换为 Oracle CLOB 对象并插入数据库的方法。该方法适用于 Oracle 数据库,通过创建临时 CLOB 并使用 Java 的 JDBC API 进行设置和插入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用jdbc 或者 hibernate
[url]http://www.weste.net/2004/11-3/12250047377.html[/url]

oracle 10g 处理clob
[url]http://blog.youkuaiyun.com/fenglibing/archive/2006/04/19/669476.aspx[/url]


好的文章
[url]http://www.herongyang.com/jdbc/Oracle-CLOB-setClob.html[/url]

解决实例:
[url]http://forum.java.sun.com/thread.jspa?threadID=349880&messageID=2778347[/url]
onvert String to CLOB and Insert into Oracle database
Jan 23, 2003 4:59 AM

Click to email this message



Hi,

I spent some time working on this, and I thought I would share it within the forum. This solution is unique to Oracle, so consider it's use carefully. It's the simplest coding I could come up with, and I have been able to insert Strings of any length using this technique with both the oci8 and thin driver when executed using Java 1.4 and Oracle 9.2. No guarantees that it will work for you. Let me know if it helps you out.
[code]
import java.sql.*;
import java.util.*;
import java.text.*;

/* -------------------------------------------------------------------
* This program demonstrates a technique for converting a large String
* to an oracle.sql.CLOB then inserting that CLOB into a database.
* I believe most of this is specific to Oracle, specifically the
* ability to create a temporary CLOB within your program.
* -------------------------------------------------------------------
*/
class TestOraCLobInsert {

public static void main (String args []) throws SQLException {

try {

DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@server:1521:sid", "uid", "pwd");

PreparedStatement ps = conn.prepareStatement("INSERT INTO CLOBTABLE VALUES (?)");

oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_CALL);

newClob.putString(1,"This string, up to 4 gigabytes will be inserted into the CLOB");

ps.setClob(1, newClob);

int rowcnt = ps.executeUpdate();

System.out.println("Successful update of "+rowcnt+" row");

ps.close();
conn.close();
}
catch (Exception e) {
System.out.println("Java Exception caught, error message="+e.getMessage());
}
}

}[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值