oracle - Store java Object as clob and retrieve -


I have a table in the oracle. In that table, one of the columns is to collect claw data and in that clab column, the object Must be included in the form of a claw.

That object must be saved as a claw and then to be re-emerged as an object.

Anyone able to store in Java is known as the obKit in the form of a clobe.

According to the example I

  import java.sql * Tried; Import java.io * *; Import oracle.jdbc.driver.OracleResultSet; Import oracle.sql.CLOB; Public class test ocrawl serializable {public static zero main (string [] args) {// test test (id integer, content clube); System.out.println ("------------------- Insert -----------------"); {Try DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ()); Connection con = DriverManager.getConnection ("Oracle server", "login", "login password"); //Class.forName("oracle.jdbc.driver.OracleDriver "); Con.setAutoCommit (wrong); // OK 1 string sql = "insert in test values ​​(1, empty_club ())"; Statement stmt = con.createStatement (); Results set rs = stmt.executeQuery (SQL); System.out.println ("------------------- Insert -----------------"); String sqll = "Select content from test where id = 1 for update"; ResultSet RSS = stmt.executeQuery (sql); 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 that contains more than 4000 characters"); Sql = "Update Test Set Content =? Where ID = 1"; Created statement pstmt = con.prepareStatement (SQL); Pstmt.setClob (1, CLOB); Pstmt.executeUpdate (); Pstmt.close (); } Con.commit (); // ok 2 // string sql1 = "insert into test values ​​(2, empty_club ())"; // ResultSet rs3 = stmt.executeQuery (sql1); String sql12 = "insert test values ​​(?,?)"; After the condition created, pstmt1 = con.prepareStatement (sql12); Pstmt1.setInt (1,2); Pstmt1.setClob (2, oracle.sql.CLOB.empty_lob ()); Pstmt1.executeUpdate (); String sqll2 = "Select content from test where id = 2 for update"; Results reset rss2 = stmt.executeQuery (sqll2); If (rss2.next ()) {CLOB clob = ((OracleResultSet) rss2) .getCLOB (1); Clob.putString (1, "affffffffffffdfdfdfdddddffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfff"); String sql1 = "update testing test content? = Id = 2"; Prepared position status pstmt = con.prepareStatement (sql1); Pstmt.setClob (1, CLOB); Pstmt.executeUpdate (); Pstmt.close (); } Con.commit (); Rss.close (); Rss2.close (); Pstmt1.close (); Rs.close (); Stmt.close (); Con.close (); System.out.println ("------------- Insert OK -------------"); } Hold (exception e) {System.out.println ("Insert:" + E); } System.out.println ("------------------- Query -----------------"); Try {string content = ""; //Class.forName("oracle.jdbc.driver.OracleDriver "); DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ()); Connection con = DriverManager.getConnection ("AnchorSaver", "ID", "Pass"); Statement stmt = con.createStatement (); String sql = "select content from test where id = 1"; Results set rs = stmt.executeQuery (SQL); If (rsnext ()) {CLOB clob = ((OracleResultSet)) .getCLOB (1); If (clob! = Null) {Reader is = Clob.JetClarkStream (); BufferedReader br = new BufferedReader (is); String s = br.readLine (); While (s! = Null) {content + = s + ","; S = br.readLine (); }}} Rs.close (); Stmt.close (); Con.close (); Println ("CLOB:" + content); System.out.println ("------------- Query is OK -------------"); } Hold (exception EE) {System.out.println ("exception:" + EE); }}}  

But they add that string to the clob but I want to add my purpose, is it possible?

Thank you in advance for your help.

I think directly could Serial Clob your object:

  object o = new object (); // Some serial Objektotputstrym out = new Objektotputstrym (Clobksetassiaistrym (0)); Out.writeObject (o); Out.close ();  

and vice versa Read:

  ObjectInputStream = (clob.getAsciiStream (new ObjectInputStream)); Object o = in.readObject (); In.close ();  

Comments