转载于:https://blog.csdn.net/wanzhix/article/details/53640312
java内容
1 Properties props = Resources.getResourceAsProperties("jdbc.properties"); 2 String url = props.getProperty("jdbc.url"); 3 String driver = props.getProperty("jdbc.driverClass"); 4 String username = props.getProperty("jdbc.username"); 5 String password = props.getProperty("jdbc.password"); 6 Class.forName(driver).newInstance(); 7 Connection conn = (Connection) DriverManager.getConnection(url, username, password);
jdbc.properties文件内容
1 jdbc.driverClass = com.mysql.jdbc.Driver 2 jdbc.url = jdbc\:mysql\://127.0.0.1\:3306/db?useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=convertToNull&allowMultiQueries\=true 3 jdbc.username = root 4 jdbc.password = root 5 jdbc.minPoolSize=2 6 jdbc.maxPoolSize=20 7 jdbc.checkoutTimeout=3000 8 jdbc.maxStatements=50 9 jdbc.testConnectionOnCheckin = false 10 jdbc.idleConnectionTestPeriod =18000
原文:https://www.cnblogs.com/carsonwuu/p/9603573.html