source: src/main/java/com/example/cookbook/dbConfig/DB.java@ 501396e

Last change on this file since 501396e was 501396e, checked in by Blazho <aleksandar.blazhevski@…>, 5 months ago

added missing files

  • Property mode set to 100644
File size: 1.4 KB
Line 
1package com.example.cookbook.dbConfig;
2
3
4import org.springframework.stereotype.Component;
5
6
7import java.sql.Connection;
8import java.sql.DriverManager;
9import java.sql.SQLException;
10
11@Component
12public 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 private static final String DB_URL = "jdbc:postgresql://localhost:9999/db_202324z_va_prj_cbdb";
18 private static final String DB_USERNAME = "db_202324z_va_prj_cbdb_owner";
19 private static final String DB_PASSWORD = "d922daf2bfec";
20
21
22 private static final String LDB_URL = "jdbc:postgresql://localhost:5432/cbdb";
23 private static final String LDB_USERNAME = "postgres";
24 private static final String LDB_PASSWORD = "04UF@bak";
25
26 private static Connection connection = null;
27
28
29
30
31
32
33 private static void setConnection() throws SQLException {
34
35 if (connection == null || connection.isClosed()){
36 connection = DriverManager.getConnection(LDB_URL, LDB_USERNAME, LDB_PASSWORD);
37 connection.createStatement().execute("set search_path to project");
38 }
39 }
40
41 public static Connection getConnection() throws SQLException {
42 setConnection();
43 return connection;
44 }
45
46
47 public static void closeConnection() throws SQLException {
48 if (connection != null){
49 connection.close();
50 }
51 }
52}
53
Note: See TracBrowser for help on using the repository browser.