zoukankan      html  css  js  c++  java
  • 使用Druid连接数据库

    配置文件

    使用properties文件配置相关数据

    --driverClassName= com.mysql.cj.jdbc.Driver            驱动加载

    --username=root                       连接数据库的用户名

    --password=                         连接数据库的密码

    --url=jdbc:mysql://127.0.0.1:3306/库名?characterEncoding=utf-8  注册驱动

    --initialSize=                         初始化池中建立的物理连接个数

    --maxActive=                         最大可活跃连接池的数量

    导包

    在lib目录下导入包:

    druid-1.1.5.jar mysql-connector-java-5.1.41-bin.jar

    数据库连接

    private static DataSource source;
        static {
            try {
                Properties properties = new Properties();
    
                InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("Druid.properties");
                properties.load(is);
                source = DruidDataSourceFactory.createDataSource(properties);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        public static Connection getConnection() throws SQLException {
            Connection connection = source.getConnection();
            return connection;
    
        }
  • 相关阅读:
    Apache xmlrpc
    认识serialVersionUID
    解压gz文件
    List of HTTP header fields
    Hadoop的Python语言封装
    httpcore in httpcomponent
    python enumerate 用法
    Hadoop Streaming Made Simple using Joins and Keys with Python « All Things Hadoop
    移位操作
    Chunked transfer encoding
  • 原文地址:https://www.cnblogs.com/Gazikel/p/14021757.html
Copyright © 2011-2022 走看看