读书人

在hibernate中实施Sql语句

发布时间: 2012-06-30 17:20:12 作者: rapoo

在hibernate中执行Sql语句
public void remove(int id){
java.sql.Connection conn=null;
java.sql.Statement stm=null;
try {
conn=this.getHibernateTemplate().getSessionFactory().openSession().connection();
stm = conn.createStatement();
String sql = "delete from × where id="+id;
stm.execute(sql);
}
catch (Exception e) {
e.printStackTrace();
}finally{
try {
if(null != stm){
stm.close();
}
if(null != conn){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

}

读书人网 >SQL Server

热点推荐