1 | package com.example.cookbook.dbConfig;
|
---|
2 |
|
---|
3 |
|
---|
4 | import org.springframework.stereotype.Component;
|
---|
5 |
|
---|
6 |
|
---|
7 | import java.sql.Connection;
|
---|
8 | import java.sql.DriverManager;
|
---|
9 | import java.sql.SQLException;
|
---|
10 |
|
---|
11 | @Component
|
---|
12 | public class DB {
|
---|
13 | // private static final String SSH_HOST = "194.149.135.130";
|
---|
14 | // private static final String SSH_USER = "t_cbdb";
|
---|
15 | // private static final String SSH_PASSWORD = "b6cd27a3";
|
---|
16 |
|
---|
17 |
|
---|
18 | //Remote database parameters
|
---|
19 | private static final String DB_URL = "jdbc:postgresql://localhost:9999/db_202324z_va_prj_cbdb";
|
---|
20 | private static final String DB_USERNAME = "db_202324z_va_prj_cbdb_owner";
|
---|
21 | private static final String DB_PASSWORD = "d922daf2bfec";
|
---|
22 |
|
---|
23 |
|
---|
24 | //Local database parameters
|
---|
25 | private static final String LDB_URL = "jdbc:postgresql://localhost:5432/cbdb";
|
---|
26 | private static final String LDB_USERNAME = "postgres";
|
---|
27 | private static final String LDB_PASSWORD = "04UF@bak";
|
---|
28 |
|
---|
29 | private static Connection connection = null;
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | private static void setConnection() throws SQLException {
|
---|
37 |
|
---|
38 | if (connection == null || connection.isClosed()){
|
---|
39 | connection = DriverManager.getConnection(LDB_URL, LDB_USERNAME, LDB_PASSWORD);
|
---|
40 | connection.createStatement().execute("set search_path to project");
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public static Connection getConnection() throws SQLException {
|
---|
45 | setConnection();
|
---|
46 | return connection;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | public static void closeConnection() throws SQLException {
|
---|
51 | if (connection != null){
|
---|
52 | connection.close();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|