📄 informationstorehibernatedao.java~182~
字号:
package org.lenovoAC.hibernateDao;
import org.lenovoAC.pojo.InformationStore;
import java.util.List;
import org.lenovoAC.dao.InformationStoreDao;
import net.sf.hibernate.Session;
import java.sql.Connection;
import java.sql.PreparedStatement;
import oracle.sql.CLOB;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.Session;
import net.sf.hibernate.Query;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* 知识库表
* 知识库: information_store
* @author not attributable
* @version 1.0
*/
public class InformationStoreHibernateDao
extends BaseDao
{
/**
* 添加
* @param is InformationStore
*/
public void insertInforStore(InformationStore is)
throws Exception
{
this.getHibernateTemplate().save(is);
Connection con= null;
ResultSet rs=null;
Session session=this.getSession();
con=session.connection();
con.setAutoCommit(false);
String sql="select * from information_store where id='"+is.getId()+"' for update";
PreparedStatement ps = con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("context");
java.io.Writer out=clob.getCharacterOutputStream();
out.write(is.getContext());
out.close();
con.commit();
con.close();
}
}
/**
* 修改
* @param is InformationStore
*/
public void updateInforStore(InformationStore is)
{
this.getHibernateTemplate().update(is);
}
/**
* 通过Sql修改
* @param is InformationStore
*/
public void updateInforStoreTwo(InformationStore is)
throws Exception
{
/*Session session=this.getSession();
try
{
String sql="update INFORMATION_STORE set Title=?,Context=?,Type=?,Time=sysdate,state=? where id=?";
Connection con = session.connection();
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,is.getTitle());
ps.setString(2,is.getContext());
ps.setString(3,is.getType());
ps.setString(4,is.getState());
ps.setString(5,is.getId());
ps.executeUpdate();
System.out.println("通过SQL修改成功!");
con.close();
ps.close();
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}*/
Connection con= null;
ResultSet rs=null;
Session session=this.getSession();
con=session.connection();
con.setAutoCommit(false);
String sqlTwo="update INFORMATION_STORE set Title=?,Type=?,Time=sysdate,state=? where id=?";
PreparedStatement ps2 = con.prepareStatement(sqlTwo);
ps2.setString(1,is.getTitle());
ps2.setString(3,is.getType());
ps2.setString(4,is.getState());
ps2.setString(5,is.getId());
ps2.executeUpdate();
String sql="select * from information_store where id='"+is.getId()+"' for update";
PreparedStatement ps = con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("context");
java.io.Writer out=clob.getCharacterOutputStream();
out.write(is.getContext());
out.close();
con.commit();
con.close();
}
}
/**
* 删除
* @param is InformationStore
*/
public void delInforStore(InformationStore is)
{
this.getHibernateTemplate().delete(is);
}
/**
* 指定ID得到对象
* @param id String
* @return InformationStore
*/
public InformationStore getInformationStore(String id)
{
return (InformationStore)this.getHibernateTemplate().get(InformationStore.class,id);
}
/**
* 通过ID删除指定对象
* @param infoId String
*/
public void delInforStoreTwo(String infoId)
{
InformationStore is=this.getInformationStore(infoId);
this.getHibernateTemplate().delete(is);
}
/**
* 得到表中所有记录
* @return List
*/
public List getAllInformationStore()
{
return this.getHibernateTemplate().loadAll(InformationStore.class);
}
/**
* 得到表中所有记录(通过时间排序)
* @return List
*/
public List getAllInformationStoreTwo()
{
String hql="from InformationStore as info order by info.time desc";
return this.getHibernateTemplate().find(hql);
}
/**
* 取得指定ID的显示标志
* @param id String
* @return String
*/
public String getState(String id)
{
InformationStore is=getInformationStore(id);
return is.getState();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -