get oracle XE Connection - Java java.sql

Java examples for java.sql:Oracle

Description

get oracle XE Connection

Demo Code


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

public class Main {
    private static final String DATA_BASE_URL = "jdbc:oracle:thin:@localhost:1521:xe";
    private static final String DB_USERNAME = "SYSTEM";
    private static final String DB_PASSWORD = "SYSTEM";
    private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";

    public static Connection getConnection() {
        Connection connection = null;
        try {//from  www  .  j  a va 2 s  .c  o  m
            Class.forName(JDBC_DRIVER);
            connection = DriverManager.getConnection(DATA_BASE_URL,
                    DB_USERNAME, DB_PASSWORD);

        } catch (SQLException sqlExp) {
            System.out.println(sqlExp.getMessage());
        } catch (ClassNotFoundException cnfExp) {
            System.out.println(cnfExp.getMessage());
        } catch (Exception exp) {
            System.out.println(exp.getMessage());
        }

        return connection;
    }
}

Related Tutorials