an example to insert data into Oracle Clob
Step1. Insert empty_clob() into the Clob column of Oracle
Step2. Set autocommit to false
Step3. Select Clob as oracle.sql.CLOB from database
Step4. Insert String into Clob
Step5. Commit
Example:
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.OracleResultSet;
import oracle.sql.CLOB;
public class TestOracleClob implements Serializable{
public static void main(String[] args)
{
//create table test (id integer,content clob);
System.out.println("-------------------insert -----------------");
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection ("oracle server",
"loginid", "loginpassword");
//Class.forName("oracle.jdbc.driver.OracleDriver");
con.setAutoCommit(false);
//Ok 1
String sql="insert into test values(1,empty_clob())";
Statement stmt=con.createStatement();
ResultSet
rs=stmt.executeQuery(sql);
System.out.println("-------------------insert -----------------");
String sqll="select content from test where id=1 for update";
ResultSet
rss=stmt.executeQuery(sqll);
if(rss.next()){
//CLOB clob = ((OracleResultSet)rss).getCLOB(1);
oracle.sql.CLOB clob= (oracle.sql.CLOB)rss.getClob("content");
clob.putString(1,"here is a string which contains more than 4000 character");
sql="update test set content=? where id=1";
PreparedStatement
pstmt=con.prepareStatement(sql);
pstmt.setClob(1,clob);
pstmt.executeUpdate();
pstmt.close();
}
con.commit();
//Ok 2
//String sql1="insert into test values(2,empty_clob())";
//ResultSet rs3=stmt.executeQuery(sql1);
String sql12="insert into test values(?,?)";
PreparedStatement
pstmt1=con.prepareStatement(sql12);
pstmt1.setInt(1,2);
pstmt
Ïà¹ØÎĵµ£º
oracle±í¿Õ¼ä²Ù×÷Ïê½â
1
2
3×÷Õߣº À´Ô´£º ¸üÐÂÈÕÆÚ£º2006-01-04
5
6
7½¨Á¢±í¿Õ¼ä
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
ÒòΪÏîĿijЩģ¿éµÄÊý¾Ý½á¹¹Éè¼ÆûÓÐÑϸñ°´ÕÕij¹æ·¶Éè¼Æ£¬ËùÒÔÖ»ÄÜ´ÓÊý¾Ý¿âÖвéѯÊý¾Ý½á¹¹£¬ÐèÒª²éѯµÄÐÅÏ¢ÈçÏ£º×Ö¶ÎÃû³Æ¡¢Êý¾ÝÀàÐÍ¡¢ÊÇ·ñΪ¿Õ¡¢Ä¬ÈÏÖµ¡¢Ö÷¼ü¡¢Íâ¼üµÈµÈ¡£
ÔÚÍøÉÏËÑË÷Á˲éѯÉÏÊöÐÅÏ¢µÄ·½·¨£¬×ܽáÈçÏ£º
Ò»£¬²éѯ±í»ù±¾ÐÅÏ¢
select
utc.column_name,utc.data_type,utc.data_le ......
alter system set nls_length_semantics='BYTE' scope=both
sql>show parameter length
NAME TYPE
------------------------------------ --------------------- ......
ÔÚ´ó¶àÊýʱºòÎÒÃÇÔÚÉè¼Æ³ÌÐòµÄʱºò¶¼×ñÑÏÂÃæµÄ²½Ö裺
1¡¢´ò¿ªÓαê
2¡¢¿ªÊ¼Ñ»·
3¡¢´ÓÓαêÖÐÈ¡Öµ
ÄÇÒ»Ðб»·µ»Ø
5¡¢´¦Àí
6¡¢¹Ø±ÕÑ»·
7¡¢¹Ø±ÕÓαê
¿ÉÒÔ¼òµ¥µÄ°ÑÕâÒ»Àà´úÂë³ÆΪÓαêÓÃÓÚÑ»·¡£µ«»¹ÓÐÒ»ÖÖÑ»·ÓëÕâÖÖÀàÐͲ»Ïàͬ£¬Õâ¾ÍÊÇFORÑ»·£¬ÓÃÓÚFORÑ»·µÄÓα갴ÕÕÕý³£µÄÉùÃ÷·½Ê½ÉùÃ÷£¬ËüµÄÓŵ ......