当前位置:网站首页>JDBC connection pool
JDBC connection pool
2022-04-23 12:57:00 【Look at the data at the top of the mountain】
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
/**
*Druid Database connection pool
*/
public class JDBCUtils {
private static DataSource ds;
static {
try {
Properties properties = new Properties();
properties.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
ds = DruidDataSourceFactory.createDataSource(properties);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Get the connection
*/
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
/**
* Release resources
*/
public static void close(Statement stat,Connection connection) throws SQLException {
close(null,stat,connection);
}
public static void close(ResultSet rs,Statement stat,Connection connection) throws SQLException {
if (rs != null){
try {
rs.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (stat != null){
try {
stat.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (connection != null){
connection.close();
}
}
/**
* Get connection pool method
*/
public static DataSource getDataSource(){
return ds;
}
}
版权声明
本文为[Look at the data at the top of the mountain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615025208.html
边栏推荐
- Jiachen chapter Genesis "inner universe" joint Edition
- 21 days learning mongodb notes
- Object. The disorder of key value array after keys
- STM32 control stepper motor (ULN2003 + 28byj)
- 【蓝桥杯】4月17日省赛刷题训练(前3道题)
- XinChaCha Trust SSL Organization Validated
- 在线计算过往日期天数,计算活了多少天
- leetcode-791. 自定义字符串排序
- [Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
- Ad20 supplementary note 3 - shortcut key + continuous update
猜你喜欢

Record the problems encountered in using v-print

What are the forms of attack and tampering on the home page of the website

22. Bracket generation

Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik

Realize several "Postures" in which a box is horizontally and vertically centered in the parent box

The El table horizontal scroll bar is fixed at the bottom of the visual window

Kubernets Getting started tutoriel

0基础可以考CPDA数据分析师证书吗

Redis deployment of cloud native kubesphere

box-sizing
随机推荐
The El table horizontal scroll bar is fixed at the bottom of the visual window
Redis deployment of cloud native kubesphere
免费试用一个月的服务器,并附上教程
Kubernetes 入門教程
31. 下一个排列
NPDP|产品经理如何做到不会被程序员排斥?
Common problems of unity (1)
If you were a golang interviewer, what questions would you ask?
Learning materials
STM32 control stepper motor (ULN2003 + 28byj)
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
教你快速开发一个 狼人杀微信小程序(附源码)
31. Next arrangement
BUUCTF WEB [BJDCTF2020]The mystery of ip
leetcode:437. Path sum III [DFS selected or not selected?]
Fashion cloud learning - input attribute summary
PC starts multiple wechat at one time
SSM框架系列——Junit单元测试优化day2-3
【蓝桥杯】4月17日省赛刷题训练(前3道题)
Can I take the CPDA data analyst certificate for 0 foundation