数据库连接池工具类 JdbcUtils
public class JdbcUtils {
private static DataSource ds;
static{
Properties prop = new Properties();
InputStream rs = JdbcUtils.class.getClassLoader().getResourceAsStream("druid.properties");
try {
prop.load(rs);
ds = DruidDataSourceFactory.createDataSource(prop);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static DataSource getDataSource(){
return ds;
}
public static void close(ResultSet rs, Statement stmt, Connection conn){
if(rs!=null) {
try {
rs.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(stmt!=null) {
try {
stmt.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
}