Java JDBC Connection Create getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection() 

Method Source Code


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

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

public class Main {
    private static String db_driver;
    private static String db_url;
    private static String db_userName;
    private static String db_passWord;

    public static Connection getConnection() {
        Connection con = null;/* w w w .  java 2s  .  com*/
        try {
            Class.forName(db_driver);
        } catch (ClassNotFoundException e) {
            System.out.println("3-ClassNotFoundException");
            e.printStackTrace();
            return null;
        }
        try {
            con = DriverManager.getConnection(db_url, db_userName, db_passWord);
        } catch (SQLException e) {
            System.out.println("4-SQLException");
            e.printStackTrace();
            return null;
        }
        return con;
    }
}

Related

  1. getConnection()
  2. getConnection()
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection(@Nonnull String connectUrl)