当前位置:网站首页>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
边栏推荐
- Van uploader upload picture implementation process, using native input to upload pictures
- 航芯技术分享 | ACM32 MCU安全特性概述
- 解决disagrees about version of symbol device_create
- leetcode:437. 路径总和 III【dfs 选还是不选?】
- XinChaCha Trust SSL Organization Validated
- Ad20 supplementary note 3 - shortcut key + continuous update
- Go language slicing operation
- Get the punch in record of nailing attendance machine
- 在线计算过往日期天数,计算活了多少天
- leetcode-791. Custom string sorting
猜你喜欢
使用Source Insight查看编辑源代码
22. 括号生成
Record some NPM related problems (messy records)
Remote sensing image classification and recognition system based on convolutional neural network
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
How to prevent the website from being hacked and tampered with
4. DRF permission & access frequency & filtering & sorting
leetcode:437. 路径总和 III【dfs 选还是不选?】
Packet capturing and sorting -- TCP protocol [8]
ZigBee CC2530 minimum system and register configuration (1)
随机推荐
只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
World Book Day: I'd like to recommend these books
Customize classloader and implement hot deployment - use loadclass
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
Recommended website for drawing result map
31. Next arrangement
洛谷P3236 [HNOI2014]画框 题解
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
Packet capturing and sorting -- TCP protocol [8]
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
Go language mapping operation
Golang implements MD5, sha256 and bcrypt encryption
Buuctf Web [gxyctf2019] no dolls
大家帮我看一下这是啥情况,MySQL5.5的。谢了
Calculate the past date and days online, and calculate the number of live days
Unable to create servlet under SRC subfile of idea
4. DRF permission & access frequency & filtering & sorting
Introduction to kubernetes
如何实现点击一下物体播放一次动画