dbconnection.java
来自「jsp+javabean+servlet案例」· Java 代码 · 共 36 行
JAVA
36 行
package db;
import java.util.ResourceBundle;
import java.sql.*;
import com.mchange.v2.c3p0.*;
import java.beans.*;
public class DBConnection {
public static Connection getConnecton()
{
Connection conn = null;
ResourceBundle res = ResourceBundle.getBundle("db");
String driver = res.getString("driver");
String url = res.getString("url");
String username = res.getString("username");
String password = res.getString("password");
ComboPooledDataSource cd = new ComboPooledDataSource();
try {
cd.setDriverClass(driver);
cd.setJdbcUrl(url);
cd.setUser(username);
cd.setPassword(password);
cd.setMaxPoolSize(100);
cd.setMinPoolSize(5);
cd.setMaxIdleTime(10000);
conn = cd.getConnection();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
return conn;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?