Description
Specialized getConnection() which uses the environment attributes for the source DB to initialize the connection
License
Open Source License
Parameter
Parameter | Description |
---|
env | ANT's env. |
Exception
Parameter | Description |
---|
Throwable | an exception |
Return
Connection
Declaration
public static final Connection getSourceConnection(final Hashtable env) 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 www. ja v a 2 s.c o m
*
* 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 {
public static final String SOURCE_DB_URL_KEY = "source.database.url";
public static final String SOURCE_DB_USERNAME_KEY = "source.database.username";
public static final String SOURCE_DB_PASSWORD_KEY = "source.database.password";
public static final String SOURCE_DB_TYPE_KEY = "source.database.type";
public static final String SOURCE_DB_DRIVER_KEY = "source.database.driver";
private static final Map<String, String> dbDrivers = new HashMap<String, String>();
/**
* Specialized getConnection() which uses the environment attributes for the source DB to initialize the connection
* @param env ANT's env.
* @return Connection
* @throws Throwable
*/
public static final Connection getSourceConnection(final Hashtable env) throws Throwable {
return getConnection(SOURCE_DB_URL_KEY, SOURCE_DB_USERNAME_KEY, SOURCE_DB_PASSWORD_KEY, SOURCE_DB_TYPE_KEY,
SOURCE_DB_DRIVER_KEY, env);
}
/**
* @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
- getConnectionWithTransaction(String dbUrl, String dbUser, String dbPassword)
- getDBConnection()
- getJdbcOdbcConnection()
- getNewConnection()
- getPhoenixConnection()
- getStatement(Map config)
- getTargetConnection()
- getTestDBConnection()
- getTRECConnection()