Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.eversis.piuw.exporter.custom;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class JDBC {
- private static JDBC instance;
- private Connection connection;
- private String url = "jdbc:mysql://localhost:3306/liferay?serverTimezone=UTC&zeroDateTimeBehavior=convertToNull&useSSL=false";
- private String username = "root";
- private String password = "password";
- private JDBC() throws SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- this.connection = DriverManager.getConnection(url, username, password);
- } catch (ClassNotFoundException ex) {
- System.out.println("Database Connection Creation Failed : " + ex.getMessage());
- }
- }
- public Connection getConnection() {
- return connection;
- }
- public static JDBC getInstance() {
- try {
- if (instance == null || instance.getConnection().isClosed()) {
- instance = new JDBC();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement