Public void insertclob () throws exception {
String content = string. valueof ("");
Try {
Bufferedreader in = new bufferedreader (
New filereader ("C:/config. xml "));
String STR;
While (STR = in. Readline ())! = NULL ){
Content = content. Concat (STR );
}
In. Close ();
} Catch (ioexception e ){
}
Statement statement = NULL;
Resultset = NULL;
Connection connection = NULL;
Try {
String user = "ahcwtest ";
String Password = "ahcwtest ";
String driver = "oracle. JDBC. Driver. oracledriver ";
String url = "JDBC: oracle: thin: @ 192.168.130.245: 1521: orcl ";
Class. forname (driver). newinstance ();
Connection = drivermanager. getconnection (URL, user, password );
// The setting is not automatically submitted
Connection. setautocommit (false );
// Create a database operation statement
Statement = connection. createstatement ();
// Define an SQL statement
Statement.exe cuteupdate ("update a set B = empty_clob ()");
String strsql = "select B from a where rownum = 1 for update ";
Resultset = statement.exe cutequery (strsql );
Clob contents = NULL;
While (resultset. Next ()){
// Retrieve the clob object
Contents = (Oracle. SQL. clob) resultset. getclob (1 );
}
Writer out = contents. getcharacteroutputstream ();
Out. Write (content );
Out. Flush ();
Out. Close ();
// Submit the database
Connection. Commit ();
} Catch (exception e ){
E. printstacktrace ();
} Finally {
}
}
-----------------------------------
Read clob content to a file
Public void readclob () throws exception {
String content = string. valueof ("");
// Try {
// Bufferedreader in = new bufferedreader (
// New filereader ("C:/test. dat "));
// String STR;
// While (STR = in. Readline ())! = NULL ){
// Content = content. Concat (STR );
//}
// In. Close ();
//} Catch (ioexception e ){
//}
Statement statement = NULL;
Resultset = NULL;
Connection connection = NULL;
Try {
String user = "ahcwtest ";
String Password = "ahcwtest ";
String driver = "oracle. JDBC. Driver. oracledriver ";
String url = "JDBC: oracle: thin: @ 192.168.130.245: 1521: orcl ";
Class. forname (driver). newinstance ();
Connection = drivermanager. getconnection (URL, user, password );
// The setting is not automatically submitted
Connection. setautocommit (false );
// Create a database operation statement
Statement = connection. createstatement ();
// Define an SQL statement
String strsql = "select B from a where rownum = 1 ";
Resultset = statement.exe cutequery (strsql );
Oracle. SQL. clob contents = NULL;
While (resultset. Next ()){
// Retrieve the clob object
Contents = (Oracle. SQL. clob) resultset. getclob ("B ");
}
Bufferedreader A = new bufferedreader (contents. getcharacterstream ());
String STR = "";
While (STR = A. Readline ())! = NULL ){
Content = content. Concat (STR );
}
Bufferedwriter out = new bufferedwriter (New filewriter ("C:/tttt.txt "));
Out. Write (content );
Out. Close ();
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Statement. Close ();
Connection. Close ();
}
}