Here you can find the source of getConnection(final String driver, final String url)
Parameter | Description |
---|---|
driver | driver class name. |
url | driver specific url. |
Parameter | Description |
---|---|
ClassNotFoundException | if driver class is not found. |
IllegalAccessException | if driver empty constructor is not public. |
InstantiationException | if an exception occurs while instantiating driver. |
SQLException | if an error occurs while making connection. |
public static Connection getConnection(final String driver, final String url) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { /**//w ww.jav a 2 s.c o m * Create a new JDBC Connection. * * @param driver * driver class name. * @param url * driver specific url. * @return Connection to database. * @throws ClassNotFoundException * if driver class is not found. * @throws IllegalAccessException * if driver empty constructor is not public. * @throws InstantiationException * if an exception occurs while instantiating driver. * @throws SQLException * if an error occurs while making connection. */ public static Connection getConnection(final String driver, final String url) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException { // create driver class, which registers with DriverManager Class.forName(driver).newInstance(); // request connection from DriverManager return DriverManager.getConnection(url); } }