zoukankan      html  css  js  c++  java
  • Java c3p0连接池

    import java.beans.PropertyVetoException;
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import javax.sql.ConnectionPoolDataSource;
    import javax.swing.text.DefaultEditorKit.InsertBreakAction;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    
    public class ConnectData {
        
        public static void main(String[] args) {
            
            System.out.println(ConnectData.getConnection());
        }
        
        private static String userName="LF";
        private static String password="LF";
        public static Connection getConnection() {
            //创建连接池
            ComboPooledDataSource dataSource = new ComboPooledDataSource();
            //通过映射来驱动
            try {
                dataSource.setDriverClass("oracle.jdbc.driver.OracleDriver");
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
            //设置url
            dataSource.setJdbcUrl("jdbc:oracle:thin:@192.168.10.105:1521:orcl");
            //设置数据库用户账号
            dataSource.setUser(userName);
            //设置数据库密码
            dataSource.setPassword(password);
            dataSource.setInitialPoolSize(5);
            dataSource.setMaxPoolSize(13);
            dataSource.setMinPoolSize(3);
            try {
                // 获取连接
                return dataSource.getConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
  • 相关阅读:
    ntp
    mknod
    timeout/timelimit
    Eclipse 包变成文件夹
    Eclipse 包变成文件夹
    Java生成随机字符串和随即生成10以内的字符串
    Java生成随机字符串和随即生成10以内的字符串
    插入排序
    插入排序
    Java 中基本类型和包装类之间的转换
  • 原文地址:https://www.cnblogs.com/lantu1989/p/6223894.html
Copyright © 2011-2022 走看看