Java JDBC Connection Create getConnection(Properties prop)

Here you can find the source of getConnection(Properties prop)

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection(Properties prop) 

Method Source Code

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

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.Properties;

public class Main {
    public static Connection getConnection(Properties prop) {
        Connection conn = null;//ww  w .j a  v  a2  s . c  o m
        try {
            if (conn == null) {
                conn = DriverManager.getConnection("jdbc:phoenix:yahoo005.nicl.cs.duke.edu:2181", prop);
                ResultSet rs = conn.prepareStatement("select count(*) from nation").executeQuery();
                while (rs.next()) {
                    System.out.println("row count " + rs.getInt(1));
                }
                System.out.println("Connection established successfully");
            }
        } catch (SQLException e) {
            System.err.println("Error in getting zookeeper connection");
            e.printStackTrace();
        }
        return conn;
    }
}

Related

  1. getConnection(final String driver, final String url)
  2. getConnection(final String driverName, final String driverUrl, final String userName, final String password)
  3. getConnection(final String url)
  4. getConnection(final String url, final String username, final String password, final String driverClass)
  5. getConnection(Properties pro)
  6. getConnection(Properties properties)
  7. getConnection(String dbName)
  8. getConnection(String dbUrl, String dbUser, String dbPassword)
  9. getConnection(String driver, String connectionString, String userName, String password)