Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Apache License

Declaration

protected static Connection getConnection() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;

public class Main {
    private static final String URL = "jdbc:mysql://localhost:3306/ir";
    private static final String USER = "root";
    private static final String PASSWORD = "wakimjr";
    private static final String DRIVER = "com.mysql.jdbc.Driver";

    protected static Connection getConnection() {
        Connection con = null;// ww w. j a va  2  s  .  c  om
        try {
            Class.forName(DRIVER);
            con = (Connection) DriverManager.getConnection(URL, USER, PASSWORD);

            return con;
        } catch (ClassNotFoundException e) {
            System.exit(-1);
            return null;
        } catch (SQLException e) {
            System.exit(-1);
            return null;
        }
    }
}

Related

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