Java JDBC MySQL Connection getDBConnection()

Here you can find the source of getDBConnection()

Description

get DB Connection

License

Open Source License

Declaration

private static Connection getDBConnection() 

Method Source Code


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

import java.sql.DriverManager;
import java.sql.Connection;

import java.sql.SQLException;

public class Main {
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/twitch";
    static final String USER = "java";
    static final String PASS = "java";

    private static Connection getDBConnection() {

        Connection dbConnection = null;

        try {/*  ww  w . j a  va2s  .co m*/

            Class.forName(JDBC_DRIVER);

        } catch (ClassNotFoundException e) {

            System.out.println(e.getMessage());

        }

        try {

            dbConnection = DriverManager.getConnection(DB_URL, USER, PASS);
            return dbConnection;

        } catch (SQLException e) {

            System.out.println(e.getMessage());

        }

        return dbConnection;

    }
}

Related

  1. getConnection(String ip, String dataBaseName, String password, String username)
  2. getConnection(String ip, String db, String user, String passWord)
  3. getConnetion(String url, String username, String password)
  4. getcount()
  5. getDBConn()
  6. getDbConnection()
  7. getDBConnection(String database)
  8. getDBConnection(String dbServer, String dbName, String dbUser, String dbPass)
  9. getDBConnection(String urlFormat, String host, Integer port, String database, String user, String password)