?? sourcedatabase.java#1.1.1.1
字號:
package com.qixuan.jdbc.common;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
import org.apache.commons.dbcp.BasicDataSource;
/**
* 實現與數據庫連接
*/
public class SourceDataBase {
private static BasicDataSource bds ;
private static String filePath = "conf/dbconfig_source.properties";
private static Properties info = new Properties();
public static final String DRIVER = "driverClass";
public static final String URL = "url";
public static final String USER = "user";
public static final String PWD = "password";
//配置一個 數據源
static {
InputStream in = null;
try {
//獲取輸入流
in = Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream(filePath);
info.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
if(in != null)
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
bds = new BasicDataSource();
//一個數據源必需的幾個要素:
//驅動類名
bds.setDriverClassName(info.getProperty(DRIVER));
//URL
bds.setUrl(info.getProperty(URL));
//USER
bds.setUsername(info.getProperty(USER));
//PASSWD
bds.setPassword(info.getProperty(PWD));
//當前連接最大維護幾個連接
bds.setMaxActive(10);
//
bds.setMaxIdle(6);
//最大等待時間:3秒
bds.setMaxWait(3000);
}
public static Connection getConnection() {
Connection con = null;
try {
con = bds.getConnection();
System.out.println(con);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -