存clob时候的java代码
Session session = getHibernateTemplate().getSessionFactory()
.openSession();
Transaction tran = session.beginTransaction();
TmInfo tmInfo = new TmInfo();
tmInfo.setContent(Hibernate.createClob(" "));//这个一定要是空格
tmInfo.setSubject(administratorForm.getSubject());
tmInfo.setPblishTime(new Date());
session.save(tmInfo);
session.flush();
session.refresh(tmInfo, LockMode.UPGRADE);
// 从页面上拿数据到实体
tmInfo.setContentString(administratorForm.getContent());
SerializableClob sc = (SerializableClob) tmInfo.getContent();
Clob wrapclob = sc.getWrappedClob();
CLOB clob = (CLOB) wrapclob;
Writer out;
try {
Writer characterOutputStream = clob.getCharacterOutputStream();//强制转换,否则会报空指针
out = characterOutputStream;
out.write(tmInfo.getContentString());
out.close();
tran.commit();
session.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.toString());
}
/***********************
************************
***********************/
取clob时候的java代码
/**********************/
Clob clob = tmInfo.getContent();// 取得Clob的值
if (clob != null) {
String clobString = "";
try {
clobString = clob.getSubString(1, (int) clob.length());// 将Clob类型的值转换成String类型的值
tmInfo.setContentString(clobString);// 通过setter方法,设置String值,然后就可以通过instance.getInfoContentToString()来取值了
} catch (SQLException e) {
e.printStackTrace();
}
}
Session session = getHibernateTemplate().getSessionFactory()
.openSession();
Transaction tran = session.beginTransaction();
TmInfo tmInfo = new TmInfo();
tmInfo.setContent(Hibernate.createClob(" "));//这个一定要是空格
tmInfo.setSubject(administratorForm.getSubject());
tmInfo.setPblishTime(new Date());
session.save(tmInfo);
session.flush();
session.refresh(tmInfo, LockMode.UPGRADE);
// 从页面上拿数据到实体
tmInfo.setContentString(administratorForm.getContent());
SerializableClob sc = (SerializableClob) tmInfo.getContent();
Clob wrapclob = sc.getWrappedClob();
CLOB clob = (CLOB) wrapclob;
Writer out;
try {
Writer characterOutputStream = clob.getCharacterOutputStream();//强制转换,否则会报空指针
out = characterOutputStream;
out.write(tmInfo.getContentString());
out.close();
tran.commit();
session.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.toString());
}
/***********************
************************
***********************/
取clob时候的java代码
/**********************/
Clob clob = tmInfo.getContent();// 取得Clob的值
if (clob != null) {
String clobString = "";
try {
clobString = clob.getSubString(1, (int) clob.length());// 将Clob类型的值转换成String类型的值
tmInfo.setContentString(clobString);// 通过setter方法,设置String值,然后就可以通过instance.getInfoContentToString()来取值了
} catch (SQLException e) {
e.printStackTrace();
}
}