Java JDBC Derby Connection createConnection(String userName, String password)

Here you can find the source of createConnection(String userName, String password)

Description

create Connection

License

Open Source License

Declaration

private static Connection createConnection(String userName, String password) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.Properties;

public class Main {
    private static Connection conn = null;
    private static String dbLocation = "droidReviewDB";
    private static String dbURL = "jdbc:derby://localhost:1527/";
    private static String driverName = "org.apache.derby.jdbc.ClientDriver";

    private static Connection createConnection(String userName, String password) {
        try {//from   ww w .  j a  va2 s  .co  m
            Class.forName(driverName);
            Properties dbProps = new Properties();
            dbProps.put("user", userName);
            dbProps.put("password", password);
            conn = DriverManager.getConnection(dbURL + dbLocation, dbProps);
        } catch (Exception except) {
            System.out.print("Could not connect to the database with username: " + userName);
            System.out.println(" password " + password);
            System.out.println("Check that the Derby Network Server is running on localhost.");
            except.printStackTrace();
        }
        return conn;
    }
}

Related

  1. cleanUpTest(Statement s, String[] testObjects)
  2. closeConnection()
  3. closeDB()
  4. createAndOpen(String databaseName)
  5. createConnection()
  6. createXATransactionView(Statement s)
  7. deleteTestData()
  8. existsInSessionTable(String id, boolean verbose)
  9. getConnection()