Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Connection getPostgresConnection() {
- try {
- DriverManager.registerDriver((Driver)
- Class.forName("org.postgresql.Driver").newInstance());
- StringBuilder url = new StringBuilder();
- url.
- append("jdbc:postgresql://"). //db type
- append("localhost:"). //host name
- append("5432/"). //port
- append("javaDB?"). //db name
- append("user=postgres&"). //login
- append("password=saw123"); //password
- System.out.println("URL: " + url + "n");
- Connection connection = DriverManager.getConnection(url.toString());
- return connection;
- } catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- return null;
- }
- Connection connection = DriverManager.getConnection(url.toString());
- Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/javaDB","postgres", "saw123");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement