Java JDBC MySQL Connection getNewDatabaseConnection(String dbUser, String dbPassword)

Here you can find the source of getNewDatabaseConnection(String dbUser, String dbPassword)

Description

get New Database Connection

License

Apache License

Declaration

public static Connection getNewDatabaseConnection(String dbUser,
            String dbPassword) throws SQLException 

Method Source Code

//package com.java2s;
/*/*w w w.ja va 2 s  .  c  om*/
 * Copyright 2013-2015 Lakshmisha Bhat
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.*;

public class Main {
    public static final String DB_URL = "jdbc:sqlserver://zinc14.pha.jhu.edu:1433;Database=owsensordb";
    private static final String COM_SQLSERVER_JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    public static Connection getNewDatabaseConnection(String dbUser,
            String dbPassword) throws SQLException {
        lookupDriver();
        return connectAndUseDatabase(dbUser, dbPassword);
    }

    private static void lookupDriver() {
        try {
            Class.forName(COM_SQLSERVER_JDBC_DRIVER);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException(
                    "Where is your MySQL JDBC Driver?", e);
        }
    }

    private static Connection connectAndUseDatabase(String dbUser,
            String dbPassword) throws SQLException {
        return DriverManager.getConnection(DB_URL, dbUser, dbPassword);
    }
}

Related

  1. getMySQLConnection(Properties props)
  2. getMySQLConnection(String cloudSqlInstance, String dbName, String userName, String password)
  3. getMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort)
  4. getMySQLConnection(String hostName, String dbName, String userName, String password)
  5. getMysqlIndices(String conString)
  6. getRssminerDB()
  7. getSearchReaderConnection()
  8. openConnection()
  9. putData(int tID, String toolID)