Java JDBC Connection Create createConnection()

Here you can find the source of createConnection()

Description

Method to return the connection

License

Apache License

Return

Connection

Declaration

public static Connection createConnection() 

Method Source Code

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

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

import java.sql.SQLException;

public class Main {
    public static Connection connection;
    public static String driver;
    public static String connectionURL;
    public static String user;
    public static String password;

    /**//from   ww w . j  av a 2 s. co  m
     * Method to return the connection
     * 
     * @return Connection
     */
    public static Connection createConnection() {
        try {
            // Loading the driver
            Class.forName(driver);
            // Creating a connection
            connection = DriverManager.getConnection(connectionURL, user, password);
        } catch (ClassNotFoundException exception) {
            System.out.println("Driver not found");
        } catch (SQLException exception) {
            System.out.println("Connection exception" + exception);
        }

        return connection;
    }
}

Related

  1. canConnect(Properties dbSettings)
  2. clearTable(String tableName, String driver, String url, String user, String password)
  3. createConnection(Properties props, String prefix)
  4. createDatabase(String dbConnectionString, String dbName, String user, String pass, String driver)
  5. createDbConnection(String dbUrl, String dbUser, String dbPass, String dbDriverClass)
  6. getAccessConn(String path)