Java JDBC Oracle Connection 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 Connection connection = null;

    public static Connection getConnection() {

        if (connection != null)
            return connection;

        try {//from  w ww .  j a va  2 s.c  om

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            //System.out.println("Where is your Oracle JDBC Driver?");
            e.printStackTrace();
            return null;

        }

        //System.out.println("Oracle JDBC Driver Registered!");

        try {

            connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "dbms", "dbms");

        } catch (SQLException e) {

            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return null;

        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }

        return connection;
    }
}

Related

  1. createDataBaseConnection(String hostName, String portNumber, String userName, String password)
  2. CreateTableScript(String dbSourceName, String db2SchemaName, String schemaList, String server, int port, String dbName, String userid, String pwd)
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection(String connectString)