Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. private static final String URL = "jdbc:mysql://localhost:3306/blog";
  2. private static final String LOGIN = "root";
  3. private static final String PASSWORD = "haslo";
  4.    
  5. public static Connection connect() throws DatabaseException{
  6.     Connection connection = null;
  7.    
  8.     try{
  9.         connection = DriverManager.getConnection(URL, LOGIN, PASSWORD);
  10.     }catch(Exception e){
  11.         throw new DatabaseException("Problem by database connection", e);
  12.     }
  13.    
  14.     return connection;
  15. }
  16.  
  17. public static void closeConnection(Connection connection) throws DatabaseException{
  18.     try{
  19.         if(connection != null)
  20.             connection.close();
  21.     }catch(SQLException e){
  22.         e.printStackTrace();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement