Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.*;

public class Main {
    private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    private static final String DB_URL = "jdbc:mysql://52.78.111.144:3306/unichat";
    private static final String USER = "jbkim";
    private static final String PASS = "1q2w3e4r!!";
    private static Connection conn = null;

    public static Connection getConnection() {

        if (conn != null) {
            return conn;
        }//w  w  w  .ja  v  a  2s . co m

        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(DB_URL, USER, PASS);
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }

        return conn;
    }
}

Related

  1. getConnection()
  2. getConnection()
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()