-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBConnection.java
32 lines (28 loc) · 1.04 KB
/
DBConnection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
public class DBConnection {
private String user = "eriknystad";
private String pwd = "";
private String host = "jdbc:postgresql://localhost:";
private String port = "5432";
private String databse = "drinks";
public Connection getConnection() {
Connection connection = null;
try {
// Load driver for PostgreSQL
Class.forName("org.postgresql.Driver");
// Create a connection to the database
connection = DriverManager.getConnection(host + port + "/" + databse, user, pwd);
if (connection != null) {
//System.out.println("Connection successful!");
return connection;
} else {
System.out.println("Connection not successful!");
}
} catch (SQLException | ClassNotFoundException ex) {
System.err.println("Error encountered: " + ex.getMessage());
}
return null;
}
}