当前位置:网站首页>JDBC连接池
JDBC连接池
2022-04-23 06:15:00 【山顶看数据】
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的数据库连接池
*/
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();
}
}
/**
* 获取连接
*/
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
/**
* 释放资源
*/
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();
}
}
/**
* 获取连接池方法
*/
public static DataSource getDataSource(){
return ds;
}
}
版权声明
本文为[山顶看数据]所创,转载请带上原文链接,感谢
https://blog.csdn.net/li1579026891/article/details/122100541
边栏推荐
- PyTorch 9. optimizer
- Use originpro express for free
- 主流 RTOS 评估
- ARMCC/GCC下的stack protector
- PyTorch 17. GPU并发
- swin transformer 转 onnx
- CMSIS CM3源码注解
- [point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation
- AUTOSAR从入门到精通100讲(八十六)-UDS服务基础篇之2F
- AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元
猜你喜欢
Use originpro express for free
Draw margin curve in arcface
1.1 pytorch and neural network
[point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation
【点云系列】Neural Opacity Point Cloud(NOPC)
“泉”力以赴·同“州”共济|北峰人一直在行动
Infrared sensor control switch
基于51单片机的体脂检测系统设计(51+oled+hx711+us100)
AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
Chapter 2 pytoch foundation 1
随机推荐
Unable to determine the device handle for GPU 0000:02:00.0: GPU is lost.
初探智能指针之std::shared_ptr、std::unique_ptr
公专融合对讲机是如何实现多模式通信下的协同工作?
美摄科技云剪辑,助力哔哩哔哩使用体验再升级
WinForm scroll bar beautification
机器学习——PCA与LDA
EMMC/SD学习小记
Intuitive understanding of torch nn. Unfold
Chapter 3 pytoch neural network toolbox
Face_ Recognition face detection
海南凤凰机场智能通信解决方案
STM32多路测温无线传输报警系统设计(工业定时测温/机舱温度定时检测等)
Error in multi machine and multi card training
SHA512/384 原理及C语言实现(附源码)
[3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion
商业广场无线对讲系统解决方案
enforce fail at inline_container.cc:222
How keras saves and loads the keras model
Modifying a column with the 'identity' pattern is not supported
Résolution du système