Advertisement
Guest User

Untitled

a guest
May 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package task.dto;
  2.  
  3. import org.apache.commons.dbcp2.BasicDataSource;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.SQLException;
  7.  
  8. public class ConnectionDB {
  9.     private final String url = "jdbc:mysql://localhost:3306/UsersDB" +
  10.             "?verifyServerCertificate=false&useSSL=true&serverTimezone=UTC"; //URL for DB
  11.     private final String userDB = "root"; //Name for DB
  12.     private final String pasDB = "qWaszx@1"; //Pas for DB
  13.     private BasicDataSource dataSource;
  14.  
  15.     //----------------------------CONNSTRUCTOR-----------------------------------
  16.     public ConnectionDB() {
  17.         dataSource = new BasicDataSource();                         //inizialize data source
  18.         dataSource.setUrl(url);
  19.         dataSource.setUsername(userDB);
  20.         dataSource.setPassword(pasDB);
  21.         dataSource.setMaxTotal(10);
  22.         dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
  23.     }
  24.  
  25.     //----------------------------GETTER-------------------------------------------
  26.     public Connection getConnnection() {
  27.         try {
  28.             return dataSource.getConnection();
  29.         } catch (SQLException e) {
  30.             e.printStackTrace();
  31.         }
  32.         return null;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement