Java JDBC Connection Create getConnection(String driver, String url, String user, String pass)

Here you can find the source of getConnection(String driver, String url, String user, String pass)

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection(String driver, String url, String user, String pass)
            throws InstantiationException, IllegalAccessException, SQLException, ClassNotFoundException 

Method Source Code


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

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

import java.sql.SQLException;

public class Main {
    public static Connection getConnection(String driver, String url, String user, String pass)
            throws InstantiationException, IllegalAccessException, SQLException, ClassNotFoundException {
        Class<?> c = Class.forName(driver);
        Driver d = (Driver) c.newInstance();
        DriverManager.registerDriver(d);
        return DriverManager.getConnection(url, user, pass);
    }//from w  w  w . j  av  a 2  s  .  c om

    public static Connection getConnection(String driver, String url)
            throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        Class<?> c = Class.forName(driver);
        Driver d = (Driver) c.newInstance();
        DriverManager.registerDriver(d);
        return DriverManager.getConnection(url);
    }
}

Related

  1. getConnection(Properties properties)
  2. getConnection(String dbName)
  3. getConnection(String dbUrl, String dbUser, String dbPassword)
  4. getConnection(String driver, String connectionString, String userName, String password)
  5. getConnection(String driver, String connectString)
  6. getConnection(String driver, String url, String username, String password)
  7. getConnection(String driverClass, String url, String user, String password)
  8. getConnection(String driverName, String urlprefix, String host, String port, String database, String user, String password)
  9. getConnection(String drvr, String url, String nm, String pass)