• javaweb-dbcp2


    package cn.itcast.utils;

    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Properties;

    import javax.sql.DataSource;

    import org.apache.commons.dbcp.BasicDataSourceFactory;


    public class JdbcUtils_DBCP {

    private static DataSource ds = null;
    static{
    try{
    InputStream in = JdbcUtils_DBCP.class.getClassLoader().getResourceAsStream("dbcpconfig.properties");
    Properties prop = new Properties();
    prop.load(in);

    BasicDataSourceFactory factory = new BasicDataSourceFactory();

    ds = factory.createDataSource(prop);
    System.out.println(ds);
    }catch (Exception e) {
    throw new ExceptionInInitializerError(e);
    }
    }

    public static Connection getConnection() throws SQLException{

    return ds.getConnection();
    }

    public static void release(Connection conn,Statement st,ResultSet rs){


    if(rs!=null){
    try{
    rs.close();
    }catch (Exception e) {
    e.printStackTrace();
    }
    rs = null;

    }
    if(st!=null){
    try{
    st.close();
    }catch (Exception e) {
    e.printStackTrace();
    }

    }

    if(conn!=null){
    try{
    conn.close();
    }catch (Exception e) {
    e.printStackTrace();
    }

    }
    }

    }

  • 相关阅读:
    javascript 闭包与函数变量作用域
    javaScript for循环
    node-inspector调试node项目
    nodejs async异步常用函数总结
    nodejs安装配置新手篇
    requirejs笔记
    使用nodejs中httpProxy代理时候出现404异常
    Bluebird-Collections
    Bluebird-Core API (三)
    Bluebird-Core API(二)
  • 原文地址:https://www.cnblogs.com/my-time/p/4513806.html
Copyright © 2020-2023  润新知