Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. public class ConnectionManager {
  2.     /**
  3.      * Klasa inicjalizujaca polaczenia z baza danych
  4.      * @return obiekt klasy java.sql.Connection opisujacy polaczenie
  5.      * @throws SQLException
  6.      */
  7.     public static Connection InitializeConnection() throws SQLException{
  8.         try {
  9.             Class.forName("org.postgresql.Driver");
  10.         } catch (ClassNotFoundException e) {
  11.             System.out.println("Bład ładowania driverem" + e);
  12.             e.printStackTrace();
  13.             System.exit(-4);
  14.         }
  15.         ConnectionConfiguration conf = ConfigurationManager.getConfiguration();
  16.         int port =0;
  17.         String host = "";
  18.         if(conf.isConfigured()){
  19.             port = conf.getPort();
  20.             host = conf.getHost();
  21.         } else {
  22.             port = conf.getDefaultPort();
  23.             host = conf.getDefaultHost();
  24.         }
  25.         String address = "jdbc:postgresql://" + host+":"
  26.                         +port + "/u3wieczorek";
  27.         db = DriverManager.getConnection(address, "u3wieczorek", "3wieczorek");
  28.        
  29.         return db;
  30.     }
  31.     /**
  32.      * obiekt klasy java.sql.Connection
  33.      * pozwalacjacy m.in wysylaczapytania do bazy
  34.      */
  35.     public static Connection db;
  36.     public static String userRole = null;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement