Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class DBConnection {
- private static final String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
- private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/mydb?verifyServerCertificate=false&useSSL=true";
- private static final String USERNAME = "root";
- private static final String PASSWORD = "root";
- private Connection connection;
- public Connection getConnection() {
- if (connection == null) {
- try {
- Class.forName(DATABASE_DRIVER);
- connection = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement