jdbc连接postgresql实例
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBUtil { private static String driver = "org.postgresql.Driver";//驱动 private static String url ="jdbc:postgresql://127.0.0.1:8432/dp_xx"; //JDBC连接URL private static String user = "search"; //用户名 private static String password = "search"; //密码 static { try { //加载驱动 Class.forName(driver); } catch (ClassNotFoundException e) { System.err.println("驱动加载出错!"); e.printStackTrace(); } } public static Connection getConnection() { Connection con = null; try { con = DriverManager.getConnection(url, user, password); } catch (SQLException e) { e.printStackTrace(); }; return con; } }
以上为获得postgresql数据库连接方式.