首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

executeUpdate()后TOMCAT死机(没反映),请教是咋回事

2012-02-27 
executeUpdate()后TOMCAT死机(没反映),请问是怎么回事。系统环境:hibernate+spring+struts,tomcat程序代码

executeUpdate()后TOMCAT死机(没反映),请问是怎么回事。
系统环境:hibernate+spring+struts,tomcat
程序代码如下:


public   void   updatePrvDAO(String   Fucode)   {
                //新增以后,需自动更新其上级功能节点编码的fuend值=0
if   (Fucode.length()> 2)
{
Session   session=(Session)   getHibernateTemplate().getSessionFactory().openSession();
Transaction   tx   =   session.beginTransaction();
Connection   con=session.connection();
try   {
String   sql= "update   bdfunc   set   fuend=0   where   fucode= ' "
+Fucode.substring(0,   (Fucode.length()-2))+ " ' ";
PreparedStatement   stmt=con.prepareStatement(sql);
stmt.executeUpdate();//执行到这点时死机
tx.commit();
}catch   (SQLException   e)   {
                        //回滚
                      tx.rollback();
                }
finally   {  
    session.close();
}
}

}

[解决办法]
既然使用hibernate就不要使用PreparedStatement了,而且你的con都不知道哪里来的,试试下面的:

Session session=(Session) getHibernateTemplate().getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
try {
String sql= "update bdfunc set fuend=0 where fucode= ' "
+Fucode.substring(0, (Fucode.length()-2))+ " ' ";
session.createSQLQuery(sql).executeUpdate();
tx.commit();
}catch (SQLException e) {
//回滚
tx.rollback();
}
finally {
session.close();
}
}

热点排行