我有一个数据库项目,我试图从netbeabs连接到数据库,我创建了一个连接类;数据库无法连接
公共类全局{
public static Connection createConnection() {
Connection conn = null;
System.out.println("Checking if Driver is registered with DriverManager.");
try{
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e){
System.out.println("Couldn't find the driver!");
System.out.println("exit.");
System.exit(1);
}
System.out.println("make a connection.");
try{
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ydb_lib", "postgres", "postgres");
System.out.println("Success.");
} catch(SQLException e){
System.out.println("Couldn't connect: exit.");
System.exit(1);
}
return conn;
}
}
,我称之为从这个方法这个类;
Connection c = Global.createConnection();
我运行程序后输出的是;
Checking if Driver is registered with DriverManager.
Couldn't find the driver!
exit.
我不能看到问题我的用户名,密码,驱动程序名称,数据库名称是正确的,所以你认为可能是什么问题?
什么是您正在使用..确保DB驱动程序JAR文件是在你的lib文件夹中的数据基地。 – Babel
是的,我认为这个问题的感谢,多数民众赞成@looser – amadeus