get oracle:thin Connection - Java java.sql

Java examples for java.sql:Oracle

Description

get oracle:thin Connection

Demo Code


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

public class Main {
    private static Connection con;
    private static String url;
    private static String user;
    private static String password;

    public static Connection getConnection() {

        try {//from  w w  w .ja  va 2  s  .  c  o  m
            url = "jdbc:oracle:thin:@localhost:1521:xe";
            user = "hr";
            password = "java1234";

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

            con = DriverManager.getConnection(url, user, password);

            System.out.println("DB Connection complete");

        } catch (Exception e) {
            System.out.println(e.toString());
            System.out.println("DB connection error");
        }

        return con;
    }
}

Related Tutorials