我想使用 JDBC。我的代码:
import java.sql.*;
import java.util.ArrayList;
import java.util.Properties;
public class test {
Connection conn;
public test() throws ClassNotFoundException, SQLException{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost/tb";
Properties props = new Properties();
props.setProperty("user","user");
props.setProperty("password","passwd");
conn = DriverManager.getConnection(url, props);
System.out.println(conn.isClosed());
}
public static void main(String[] args) {
try{
test t = new test();
} catch (Exception e){
e.printStackTrace();
}
}
}
我的软件:postgres 9.1,java 1.7
我的尝试:
ziel@gad ~/java/test $ ls
postgresql-9.1-902.jdbc4.jar test.java
ziel@gad ~/java/test $ javac test.java
ziel@gad ~/java/test $ java -cp postgresql-9.1-902.jdbc4.jar test
Error: Could not find or load main class test
据谷歌的人说,这应该加载驱动程序。我究竟做错了什么?