Here you can find the source of getMysqlConnection(final String url)
Parameter | Description |
---|---|
url | a Mysql URL. |
public static Connection getMysqlConnection(final String url) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { /** Mysql Driver. */ public static final String MYSQL_DRIVER_CLASSNAME = "com.mysql.jdbc.Driver"; /**//from www . ja va 2 s . co m * Get a mysql connection from a URL. * * Calls getConnection(MYSQL_DRIVER_CLASSNAME, url). * * @param url * a Mysql URL. * @return a Connection to a Mysql database. */ public static Connection getMysqlConnection(final String url) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException { return getConnection(MYSQL_DRIVER_CLASSNAME, url); } /** * 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); } }