How to get JDBC Connection to ORACLE Database in Java?

DeeKay April 29, 2011 at 8:51 pm · java.sql

Below code snippet shows you to get the JDBC connection in java for ORACLE DB. To get the JDBC connection you will need JDBC Driver Jar for ORACLE Database.

 * Created on 04-2011 Copyright(c) All Rights Reserved.
package com.kodehelp.javasql;

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

 * Created by
 * Date: 4/29/11
public class GetOracleConnection {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        final String driver = "oracle.jdbc.driver.OracleDriver";
        final String url = "jdbc:oracle:thin:@HOST:PORT:SID";
        final String USERNAME = "USERNAME";
        final String PASSWORD = "PASSWORD";
        Class.forName(driver); // load Oracle driver
        Connection conn = DriverManager.getConnection(url, USERNAME, PASSWORD);