本帖最后由 ying 于 2013-1-8 13:15 编辑
package utile;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class DBUtileC3P0 {
private static ComboPooledDataSource cpd = null;
private static DBUtileC3P0 instance = null;
String className = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String username = "system";
String password = "system";
private DBUtileC3P0()
{
//设置jdbc信息
cpd.setUser(username);
cpd.setPassword(password);
cpd.setJdbcUrl(url);
try {
cpd.setDriverClass(className);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
//连接池的设置
cpd.setInitialPoolSize(30);
cpd.setMaxPoolSize(1000);
cpd.setMinPoolSize(10);
}
public static DBUtileC3P0 getInstance()
{
if(instance == null)
{
instance = new DBUtileC3P0();
}
return instance;
}
public Connection getConnection() throws SQLException
{
return cpd.getConnection();
}
public static void main(String[] args) throws SQLException {
Connection conn = DBUtileC3P0.getInstance().getConnection();
if( null != conn)
{
System.out.println("数据库连接失败");
}
}
}
|
-
未命名.jpg
(51.13 KB, 下载次数: 33)
数据库连接失败的输出
|