首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

在hibernate中实施Sql语句

2012-06-30 
在hibernate中执行Sql语句public void remove(int id){java.sql.Connection connnulljava.sql.Statement

在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();
            }
     }  
          
    } 

热点排行