java与postgresql连接示例,可以测试postgresql驱动加的对不对。
public static void postgre() { Connection c = null; try { Class.forName("org.postgresql.Driver"); c = DriverManager .getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "post"); } catch (Exception e) { e.printStackTrace(); System.err.println(e.getClass().getName()+": "+e.getMessage()); System.exit(0); } System.out.println("Opened database successfully"); }