Insert Database
Clob tempclob = NULL; try {connection conn = getconnection (); preparedstatement = conn. preparestatement ("Update program_history Set details =? Where id = 12 "); tempclob = clob. createtemporary (Conn, true, clob. duration_session); tempclob. open (clob. mode_readwrite); writer tempclobwriter = tempclob. getcharacteroutputstream (); tempclobwriter. write (clobdata); tempclobwriter. flush (); tempclobwriter. close (); tempclob. close (); pstmt. setclob (1, tempclob); pstmt.exe cute ();} catch (exception ex) {// trap errors system. out. println ("error inserting Clob: "+ ex. tostring (); Ex. printstacktrace ();} finally {If (tempclob! = NULL) tempclob. freetemporary (); opstmt. Close (); Conn. Close ();}
Obtain
Oracle Rs. getclob ("") to string
Oracle Data is defined as a clob field. If it is obtained using the Rs. getstring () method, the value is always NUL and cannot be retrieved.
Use Rs. getclob () to obtain the clob type.
Convert clob type to string type
Method 1:
Rs = pstmt.exe cutequery (); While (RS. next () {reader = Rs. getclob ("afterstepscript "). getcharacterstream (); bufferedreader r = new bufferedreader (Reader); stringbuffer sb = new stringbuffer (); string line; try {While (line = R. readline ())! = NULL) {sb. append (line); // sb. append ("\ r \ n") ;}} catch (ioexception e) {e. printstacktrace ();} string afterstepscript = sb. tostring ();
Method 2
Clob = Rs. getclob ("insidescript"); string insidescript = ""; if (clob! = NULL) {insidescript = clob. getsubstring (long) 1, (INT) clob. Length ());}