Java JDBC Connection Create getConnection()

Here you can find the source of getConnection()

Description

Clear the database.

License

Open Source License

Parameter

Parameter Description
connection the connection.

Exception

Parameter Description
Exception to JUnit.

Declaration

protected static Connection getConnection() throws Exception 

Method Source Code

//package com.java2s;
import java.io.FileInputStream;

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

import java.util.Properties;

public class Main {
    private static Connection connection;

    /**/*www .  java  2s .c  om*/
     * Clear the database.
     * 
     * @param connection
     *            the connection.
     * 
     * @throws Exception
     *             to JUnit.
     */
    protected static Connection getConnection() throws Exception {
        if (connection == null) {

            Properties p = new Properties();
            FileInputStream in = new FileInputStream(
                    "test_files/stress/database.properties");
            p.load(in);
            in.close();
            Class.forName(p.getProperty("DatabaseDriver"));
            return DriverManager.getConnection(
                    p.getProperty("DatabaseUrl"),
                    p.getProperty("username"), p.getProperty("password"));
        }
        return connection;
    }
}

Related

  1. getAccessConn(String path)
  2. getConnect(String driver, String url, String user, String password)
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()