Druid配置文件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8f7507d3f03c92a089fd780aaaa25855.png)
Druid连接池工具类实现代码
public class JDBCUtils {
private static DataSource ds = null;
static{
try {
Properties pro = new Properties();
pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
ds = DruidDataSourceFactory.createDataSource(pro);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
public static void close(ResultSet rs, Statement stmt, Connection conn)
{
if (rs != null)
{
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt != null)
{
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null)
{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close(Statement stmt, Connection conn)
{
close(null,stmt,conn);
}
public static DataSource getDataSource(){
return ds;
}
}