The unit used Oracle to store the string type into the database CLOB, to view the data online to find a solution. As follows:
1 Public classClobtest {2 3 StaticString url = "JDBC:ORACLE:THIN:@10.12.10.18:1521:ORCL"; 4 StaticString user = "cwbe1_9999"; 5 StaticString pwd = "or777"; 6 StaticString Text = "This is the data to be inserted into the CLOB, update the data!" "+" Update "; 7 8 Private Static intClobimport ()throwsClassNotFoundException, SQLException {9Drivermanager.registerdriver (Neworacledriver ()); TenConnection conn = drivermanager.getconnection (URL, user, pwd);//Get the Connection object OneString sql = "INSERT into Etlneedparam (f_key,f_value) VALUES (' Defaultpo ',?)";//the SQL statement to execute APreparedStatement stmt = conn.preparestatement (sql);//Load SQL statements - //preparedstatement Support SQL with question mark? , can be dynamically replaced? The content. -Reader Clobreader =NewStringReader (text);//turn text into a stream form theStmt.setcharacterstream (1, Clobreader, Text.length ());//Replace in SQL statement? - intnum = Stmt.executeupdate ();//Execute SQL - if(num > 0) { -System.out.println ("OK"); +}Else { -System.out.println ("NO"); + } A Stmt.close (); at Conn.close (); - returnnum; - } - - Private Static intClobupdate (String key)throwsClassNotFoundException, SQLException { - inDrivermanager.registerdriver (Neworacledriver ()); -Connection conn = drivermanager.getconnection (URL, user, pwd);//Get the Connection object toString sql = "Update etlneedparam set f_value =?" where F_key =? ";//the SQL statement to execute +PreparedStatement stmt = conn.preparestatement (sql);//Load SQL statements - //preparedstatement Support SQL with question mark? , can be dynamically replaced? The content. theReader Clobreader =NewStringReader (text);//turn text into a stream form *Stmt.setstring (2, key); $Stmt.setcharacterstream (1, Clobreader, Text.length ());//Replace in SQL statement? Panax Notoginseng intnum = Stmt.executeupdate ();//Execute SQL - if(num > 0) { theSystem.out.println ("OK"); +}Else { ASystem.out.println ("NO"); the } + Stmt.close (); - Conn.close (); $ returnnum; $ } - - Private StaticString Clobexport ()throwsclassnotfoundexception, SQLException, IOException { the -CLOB CLOB =NULL; WuyiString sql = "Select F_value from etlneedparam where F_key = ' test1 '"; theDrivermanager.registerdriver (Neworacledriver ()); -Connection conn = drivermanager.getconnection (URL, user, pwd);//Get the Connection object WuPreparedStatement stmt =conn.preparestatement (SQL); -ResultSet rs =Stmt.executequery (); AboutString content = ""; $ if(Rs.next ()) { -CLOB = (Oracle.sql.CLOB) rs.getclob ("F_value");//get clob field str - //Note: The data is not available with rs.getstring ("str") and NULL is returned; -Content =clobtostring (CLOB); A } + Stmt.close (); the Conn.close (); - returncontent; $ } the the //Convert a character clob to a string type the the Public StaticString clobtostring (CLOB CLOB)throwsSQLException, IOException { -String restring = ""; inReader is = Clob.getcharacterstream ();//Get the Flow theBufferedReader br =NewBufferedReader (IS); theString s =Br.readline (); AboutStringBuffer SB =NewStringBuffer (); the //the execution loop takes all the strings out and pays the value to StringBuffer from StringBuffer to string the while(s! =NULL) { the Sb.append (s); +s =Br.readline (); - } theRestring =sb.tostring (); Bayi returnrestring; the } the - Public Static voidMain (string[] args)throwsioexception,classnotfoundexception, SQLException { - //System.out.println (Clobimport ()); theSystem.out.println (Clobupdate ("FMO")); theSystem.out.println (Clobupdate ("EPO")); the the //System.out.println (Clobexport ()); - the}
Transferred from: http://bestxiaok.iteye.com/blog/1027733
Java Oracle CLOB string Large string storage "go"