In POJO, a large String object can be declared as a java. lang. String or java. SQL. Clob type. When a program loads Clob data from a database, it only loads a logical pointer of Clob data. You must use the Clob. getCaracterStream () method to obtain the data input stream of the Clob type before obtaining the big object data.
In POJO, a large String object can be declared as a java. lang. String or java. SQL. Clob type. When a program loads Clob data from a database, it only loads a logical pointer of Clob data. You must use the Clob. getCaracterStream () method to obtain the data input stream of the Clob type before obtaining the big object data.
In POJO, a large String object can be declared as a java. lang. String or java. SQL. Clob type.
When a program loads Clob data from a database, it only loads a logical pointer of Clob data. You must use the Clob. getCaracterStream () method to obtain the data input stream of the Clob type before obtaining the big object data.
See the following code
Package dao; import java. io. bufferedReader; import java. io. IOException; import java. io. reader; import java. math. bigDecimal; import java. SQL. clob; import java. SQL. SQLException; import org. hibernate. lobHelper; import org. hibernate. query; import org. hibernate. session; import org. hibernate. transaction; import entity. clobtable; import Factory. hibernateSessionFactory; public class ClobDao {private Session session = n Ull; private Transaction tran = null; public ClobDao () {session = HibernateSessionFactory. getSession ();} public void saveClob (BigDecimal id, String content) {Clobtable ct = new Clobtable (); ct. setId (id); LobHelper lh = session. getLobHelper (); ct. setContent (lh. createClob (content); tran = session. beginTransaction (); try {session. save (ct); tran. commit (); System. out. println ("inserted successfully! ");} Catch (Exception e) {tran. rollback (); System. out. println ("insertion failed") ;}} public void getClob (BigDecimal id) {String hql = "from Clobtable where id =? "; Query query = session. createQuery (hql); query. setBigDecimal (0, id); Clobtable ct = (Clobtable) query. uniqueResult (); Clob clob = ct. getContent (); try {Reader reader = clob. getCharacterStream (); BufferedReader br = new BufferedReader (reader); String content = br. readLine (); System. out. println (content);} catch (SQLException e) {e. printStackTrace (); System. out. println ("read failed! ");} Catch (IOException e) {System. out. println (" read failed! ");}}}