博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义JDBCUitls
阅读量:4943 次
发布时间:2019-06-11

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

package utils;import java.sql.Connection;import java.sql.SQLException;import javax.sql.DataSource;import com.mchange.v2.c3p0.ComboPooledDataSource;public class JdbcUtils {    private static final ComboPooledDataSource DATASOURCE = new ComboPooledDataSource();    private static final ThreadLocal
TL = new ThreadLocal
(); public static DataSource getDataSource() { return DATASOURCE; } public static Connection getConn() throws SQLException { if (TL.get() == null) { TL.set(DATASOURCE.getConnection()); } return TL.get(); } public static void beginTranscation() throws SQLException { if (TL.get() == null) { TL.set(DATASOURCE.getConnection()); } TL.get().setAutoCommit(false); } public static void committranscation() throws SQLException { if (TL.get() == null) { TL.set(DATASOURCE.getConnection()); } TL.get().commit(); } public static void roolbackTranscation() throws SQLException { if (TL.get() == null) { TL.set(DATASOURCE.getConnection()); } TL.get().rollback(); }}

 

转载于:https://www.cnblogs.com/laodang/p/9504582.html

你可能感兴趣的文章