这是如何我已经做了连接:(我不知道这是否是“最佳实践”,但它的工作原理)
导入驱动程序:
- 鼠标右键点击你的项目
- 选择属性
- 选择
Java build path
- 选择
Add external JARS..
和选择位置JDBC驱动程序。
这里是我的代码:
try{
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe){
System.out.println("Could not find the JDBC driver!");
System.exit(1);
}
Connection conn = null;
try {
conn = DriverManager.getConnection
(String url, String user, String password);
} catch (SQLException sqle) {
System.out.println("Could not connect");
System.exit(1);
}
URL可以是以下格式之一:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database
定义 “既不工作”。你有没有收到一条消息,或者是什么? – 2008-10-14 02:08:35