博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DBHelper
阅读量:7217 次
发布时间:2019-06-29

本文共 1416 字,大约阅读时间需要 4 分钟。

hot3.png

public class DBHelper {		public static DataSource ds = JNDIDataSource.getDS();	public static ThreadLocal
container = new ThreadLocal
(); public static ThreadLocal
getContainer(){ return container; } public static DataSource getDataSource(){ return ds; } public static void startTransaction(){ Connection conn = container.get(); if(conn==null){ conn = getConnection(); container.set(conn); } try{ conn.setAutoCommit(false); }catch(SQLException e){ throw new RuntimeException(e.getMessage(),e); } } public static void commit(){ Connection conn = container.get(); if(conn!=null){ try{ conn.commit(); }catch (SQLException e) { throw new RuntimeException(e.getMessage(),e); } } } public static void rollback(){ Connection conn = container.get(); if(conn!=null){ try{ conn.rollback(); }catch(SQLException e){ throw new RuntimeException(e.getMessage(),e); } } } public static void close(){ Connection conn = container.get(); if(conn!=null){ try{ conn.close(); }catch(SQLException e){ }finally{ container.remove(); } } } public static Connection getConnection(){ try{ return ds.getConnection(); }catch(Exception e){ throw new RuntimeException(); } } public static QueryRunner getQueryRunner(){ QueryRunner qr = new QueryRunner(ds); return qr; } }

转载于:https://my.oschina.net/u/561475/blog/104342

你可能感兴趣的文章
python:浅析python 中__name__ = '__main__' 的作用
查看>>
修改tomcat端口后不能IP访问问题
查看>>
review board
查看>>
URAL 1495 One-two, One-two 2
查看>>
牛客国庆集训派对Day3 G Stones
查看>>
虚函数简单总结
查看>>
插入排序--算法导论
查看>>
NoSQL -- Redis使用
查看>>
处理iphone的 .play() 不能播放问题
查看>>
jetty404web界面服务器信息隐藏
查看>>
22个Photoshop网页设计教程网站推荐
查看>>
如何让程序员更容易的开发Web界面?重构SmartAdmin展示TinyUI
查看>>
centos7 python2和python3共存
查看>>
rhel6.2配置在线yum源
查看>>
分级聚类算法
查看>>
Web Services 入门(之二)
查看>>
随机模拟MCMC和Gibbs Sampling
查看>>
网络安全是一种态度
查看>>
POJ1131 Octal Fractions
查看>>
mysql-ulogd2.sql
查看>>