4 changed files with 61 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||||||
|
package constants; |
||||||
|
|
||||||
|
public class PSGQL { |
||||||
|
public final String url = "jdbc:postgresql://localhost:5432/ScanDB"; |
||||||
|
public final String user = "ncaughey"; |
||||||
|
public final String password = ""; |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
package dto; |
||||||
|
|
||||||
|
// import constants.PSGQL;
|
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
public class ConnectDB{ |
||||||
|
|
||||||
|
// private final String url = "jdbc:postgresql://localhost/dvdrental";
|
||||||
|
// private final String user = "postgres";
|
||||||
|
// private final String password = "<add your password>";
|
||||||
|
private final String url = "jdbc:postgresql://localhost:5432/scandb"; |
||||||
|
private final String user = "postgres"; |
||||||
|
private final String password = "password"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect to the PostgreSQL database |
||||||
|
* |
||||||
|
* @return a Connection object |
||||||
|
*/ |
||||||
|
public Connection connect() { |
||||||
|
Connection conn = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(url, user, password); |
||||||
|
System.out.println("Connected to the PostgreSQL server successfully."); |
||||||
|
} catch (SQLException e) { |
||||||
|
System.out.println(e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return conn; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue