get Oracle Connection - Java java.sql

Java examples for java.sql:Oracle

Description

get Oracle Connection

Demo Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

public class Main {
    public static void main(String[] argv) throws Exception {
        String url = "java2s.com";
        String user = "java2s.com";
        String pwd = "java2s.com";
        System.out.println(getOracleConn(url, user, pwd));
    }/*from   w  w w  .jav  a2s  . c om*/

    public static Connection getOracleConn(String url, String user,
            String pwd) {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            return DriverManager.getConnection(url, user, pwd);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}

Related Tutorials