Oracle provides OCI and THIN type of JDBC drivers for both server and client side.Mainly they are reffered as Type 2 and Type 4 drivers. The basic format of a service URL is:

 jdbc:oracle:thin:[<user>/<password>]@//<host>[:<port>]/<service>

 

Example below connects to Oracle Database instance using JDBC-Thin Type 4 Driver.

 import java.sql.*;

public class getOracleConnection 
{
        public static void main(String[] args) 
        {
                DB db = new DB();
                Connection conn=db.dbConnect(
                  "jdbc:oracle:thin:@localhost:1521/test", "scott", "tiger");
        }

}

class DB
{
        public DB() {}

        public Connection dbConnect(String db_connect_string, 
          String db_userid, String db_password)
        {
                try
                {
                        DriverManager.registerDriver(
                          new oracle.jdbc.OracleDriver());
                          
                        Connection conn = DriverManager.getConnection(
                          db_connect_string, db_userid, db_password);
        
                        System.out.println("connected");
                        return conn;
                        
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                        return null;
                }
        }
};