Java JDBC Connection Create getConnection(String dbName)

Here you can find the source of getConnection(String dbName)

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection(String dbName) 

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 {
    private static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
    private static final String PROTOCOL = "jdbc:derby:";

    public static Connection getConnection(String dbName) {
        try {/*www.  j a  va2 s . c  o  m*/
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            return DriverManager.getConnection(PROTOCOL + dbName
                    + ";create=true");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getConnection(final String url)
  2. getConnection(final String url, final String username, final String password, final String driverClass)
  3. getConnection(Properties pro)
  4. getConnection(Properties prop)
  5. getConnection(Properties properties)
  6. getConnection(String dbUrl, String dbUser, String dbPassword)
  7. getConnection(String driver, String connectionString, String userName, String password)
  8. getConnection(String driver, String connectString)
  9. getConnection(String driver, String url, String user, String pass)