跟我学hibernate框架技术——在hibernate中应用jdbc实现操作数据库表实例内容摘要:

@Override public void execute(Connection jdbcConnection) throws SQLException { String updateSQL=update Book set BookName=39。 Hibernate 应用开发 39。 where book_id=39。 + bookID+39。 PreparedStatement stmt=null。 try { stmt = (updateSQL)。 } catch (SQLException e1) { ()。 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 7/15 页 7 } try { ()。 } catch (SQLException e) { ()。 } } } 然后在 DAO 中的相关方法内应用前面的实现 Work 接口的数据操作类 public boolean doUpdateBookDataToDB_JDBC(String bookID) throws HibernateException, UnsupportedEncodingException { Session session = null。 Transaction tx = null。 try { session = ()。 tx = ()。 (new JDBCUpdateDB(bookID))。 ()。 } catch (HibernateException he){ if (tx != null){ ()。 } throw he。 } finally { ()。 } 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 8/15 页 8 return true。 } 以上程序演示了在 版本中如何绕过 Hibernate API,直接通过 JDBC API 访问数据库的过程。 应用程序通过 Session 的 connection()方法获得该 Session 使用的数据库连接,然后通过它创建 PreparedStatement 对象并执行 SQL 语句。 示例的执行结果截图如下: 因此,当应用 Hibernate 进行数据库表查询时的效率比较低的时候,可以应用该方式提高性能。 ( 2) Hibernate 版的实现示例 public boolean doUpdateBookDataToDB_JDBC(String bookID) throws HibernateException, UnsupportedEncodingException { Session session = null。 Transaction tx = null。 try { session = ()。 tx = ()。 Connection con=()。 String updateSQL=update Book set BookName=39。 Hibernate 应用开发 39。 where book_id=39。 + bookID+39。 PreparedStatement stmt=null。 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 9/15 页 9 try { stmt = (updateSQL)。 } catch (SQLException e1) { ()。 } try { ()。 } catch (SQLException e) { ()。 } ()。 } catch (HibernateException he){ if (tx != null){ ()。 } (在 doInsertB。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。