Description
get Connection
License
Open Source License
Parameter
Parameter | Description |
---|
url | a parameter |
username | a parameter |
password | a parameter |
driverClass | a parameter |
Exception
Parameter | Description |
---|
Throwable | an exception |
Return
Connection
Declaration
public static final Connection getConnection(final String url, final String username, final String password,
final String driverClass) throws Throwable
Method Source Code
//package com.java2s;
/* **********************************************************************
/*
* NOTE: This copyright does *not* cover user programs that use Hyperic
* program services by normal system calls through the application
* program interfaces provided as part of the Hyperic Plug-in Development
* Kit or the Hyperic Client Development Kit - this is merely considered
* normal use of the program, and does *not* fall under the heading of
* "derived work".//from w w w .j a va2 s.c om
*
* Copyright (C) [2004-2012], VMware, Inc.
* This file is part of Hyperic.
*
* Hyperic is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
public class Main {
private static final Map<String, String> dbDrivers = new HashMap<String, String>();
/**
* @param url
* @param username
* @param password
* @param driverClass
* @return Connection
* @throws Throwable
*/
public static final Connection getConnection(final String url, final String username, final String password,
final String driverClass) throws Throwable {
Class.forName(driverClass);
return DriverManager.getConnection(url, username, password);
}
/**
* G
* @param urlKey
* @param usernameKey
* @param passwordKey
* @param dbTypeKey
* @param driverClassKey
* @param env
* @return
* @throws Throwable
*/
public static final Connection getConnection(final String urlKey, final String usernameKey,
final String passwordKey, final String dbTypeKey, final String driverClassKey, final Hashtable env)
throws Throwable {
final String dbUrl = (String) env.get(urlKey);
final String username = (String) env.get(usernameKey);
final String password = (String) env.get(passwordKey);
String driver = (String) env.get(driverClassKey);
final String dbType = (String) env.get(dbTypeKey);
driver = (String) dbDrivers.get(dbType);
return getConnection(dbUrl, username, password, driver);
}
}
Related
- getConnection()
- getConnection(@Nonnull String connectUrl)
- getConnection(final String driver, final String url)
- getConnection(final String driverName, final String driverUrl, final String userName, final String password)
- getConnection(final String url)
- getConnection(Properties pro)
- getConnection(Properties prop)
- getConnection(Properties properties)
- getConnection(String dbName)