Java JDBC Connection Pool getDatabaseConnection(String propertiesFile)

Here you can find the source of getDatabaseConnection(String propertiesFile)

Description

get Database Connection

License

Open Source License

Declaration

public static Connection getDatabaseConnection(String propertiesFile)
            throws ClassNotFoundException, SQLException, FileNotFoundException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Main {
    public static Connection getDatabaseConnection(String propertiesFile)
            throws ClassNotFoundException, SQLException, FileNotFoundException, IOException {

        Properties properties = new Properties();
        properties.load(new FileInputStream(propertiesFile));

        String jdbcClassName = properties.getProperty("jdbc.class.name");
        String jdbcDatabase = properties.getProperty("jdbc.database");
        String jdbcUsername = properties.getProperty("jdbc.username");
        String jdbcPassword = properties.getProperty("jdbc.password");
        // output(isSilent, "Connecting to database [" + jdbcDatabase + "]");

        Class.forName(jdbcClassName);
        return DriverManager.getConnection(jdbcDatabase, jdbcUsername, jdbcPassword);
    }/*from   ww  w .  ja v  a 2 s.  c o m*/
}

Related

  1. getConnection()
  2. getConnectionFromPool()