oracle java 插入 clob insert clob hibernate

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

oracle 10g 处理clob
[url]http://blog.csdn.net/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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Oracle数据库插入大段文本数据的解决方法主要有以下几种: 1. 使用INSERT语句:可以使用INSERT语句将大段文本数据直接插入到包含CLOB列的表中。可以通过使用bind变量来优化插入效率,同时使用LOB locator进行处理。 2. 使用PL/SQL块:在PL/SQL中可以使用DBMS_LOB包中的SUBSTR和APPEND函数来处理CLOB数据的插入操作。首先,使用SUBSTR函数将大段文本数据划分为较小的片段,然后逐个将这些片段使用APPEND函数插入CLOB列中。 3. 使用JAVA存储过程:如果在JAVA环境中,可以编写JAVA存储过程来处理大段文本数据的插入操作。通过调用JAVA存储过程,可以使用Oracle提供的LOB接口来处理CLOB数据的插入。 无论使用哪种方法插入CLOB数据,都需要注意以下几点: 1. 考虑到CLOB数据的大小限制,默认情况下Oracle支持最大4GB的CLOB数据。需要确保目标表中CLOB列的大小足够容纳要插入的文本数据。 2. 考虑到性能问题,尽量避免一次性插入过大的CLOB数据。可以将大文本数据划分为较小的片段进行逐个插入。 3. 在插入CLOB数据之前,需要确保目标表中的CLOB列已经创建,并且在插入操作之前分配了足够的空间。 总之,根据具体的需求和环境条件,可以选择使用不同的方法来向Oracle数据库中插入大段文本数据。在插入过程中,要考虑到数据大小限制、性能优化和CLOB列的准备等因素,以确保插入操作的顺利进行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值