Description
Establishes a connection to a database.
License
Open Source License
Parameter
Parameter | Description |
---|
dbServer | - database server |
dbName | - name of the database to use |
dbUser | - database username |
dbPass | - database password |
Exception
Parameter | Description |
---|
ClassNotFoundException | an exception |
SQLException | an exception |
Declaration
public static Connection getDBConnection(String dbServer, String dbName, String dbUser, String dbPass)
throws ClassNotFoundException, SQLException
Method Source Code
//package com.java2s;
/**//from w w w . j a va 2 s .c o m
* Candybean is a next generation automation and testing framework suite.
* It is a collection of components that foster test automation, execution
* configuration, data abstraction, results illustration, tag-based execution,
* top-down and bottom-up batches, mobile variants, test translation across
* languages, plain-language testing, and web service testing.
* Copyright (C) 2013 SugarCRM, Inc. <candybean@sugarcrm.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
/**
* Establishes a connection to a database.
*
* @author Jason Lin (ylin)
*
* @param dbServer - database server
* @param dbName - name of the database to use
* @param dbUser - database username
* @param dbPass - database password
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getDBConnection(String dbServer, String dbName, String dbUser, String dbPass)
throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection(
"jdbc:mysql://" + dbServer + "/" + dbName + "?useUnicode=true&characterEncoding=utf-8", dbUser,
dbPass);
}
}
Related
- getcount()
- getDBConn()
- getDbConnection()
- getDBConnection()
- getDBConnection(String database)
- getDBConnection(String urlFormat, String host, Integer port, String database, String user, String password)
- getDMPConn()
- getGoogleCloudDBConnection()
- getIonMassList()