当前位置:网站首页 > R语言数据分析 > 正文

druid连接池配置详解(druid连接池工具类)



/ * Druid连接池的工具类 */ public class JDBCUtils { //1.定义成员变量 private static DataSource ds; static { try { //1.加载配置文件 Properties pro = new Properties(); pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties")); //2.获取DataSource 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(Statement stmt,Connection conn){ /*if (stmt!=null){ try { stmt.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } if (conn!=null){ try { conn.close();//归还连接 } catch (SQLException throwables) { throwables.printStackTrace(); } }*/ close(null,stmt,conn); } 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 DataSource getDataSource(){ return ds; } }
到此这篇druid连接池配置详解(druid连接池工具类)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在 编程的领域有一番成就!

版权声明


相关文章:

  • hprof怎么读(hpld怎么读)2026-05-24 22:09:07
  • pycharm怎么删除干净(怎么把pycharm删除干净)2026-05-24 22:09:07
  • impdp参数说明(impdp parallel参数)2026-05-24 22:09:07
  • chronyd(chrony查看同步情况)2026-05-24 22:09:07
  • codeformer(codeformer中文版下载)2026-05-24 22:09:07
  • treesoft官网(tree studio)2026-05-24 22:09:07
  • aipods蓝牙耳机(airpod蓝牙耳机)2026-05-24 22:09:07
  • dhcp client怎么关闭(dhcp server怎么关闭)2026-05-24 22:09:07
  • prp离心后分层图(prp制作对离心机的要求)2026-05-24 22:09:07
  • yarn logs -applicationid命令(yarn build命令)2026-05-24 22:09:07
  • 全屏图片