Thursday, July 30, 2015

Connect to Oracle Database through JDBC Thin/OCI Drivers


Yesterday, there was friend asked me about the jdbc connection. I have performed simple testing on his case.

The two most common methods of connecting to Oracle databases via JDBC are the Oracle Thin JDBC driver and the Oracle OCI JDBC driver.


Oracle JDBC Thin Driver Format - require Oracle JDBC driver jar file
Oracle JDBC Thin using a Service Name
jdbc:oracle:thin:@//<host>:<port>/<service_name>

Oracle JDBC Thin using an SID
jdbc:oracle:thin:@<host>:<port>:<SID>

Note: Support for SID is being phased out. Oracle recommends that users switch over to using service names.

Oracle JDBC Thin using a TNSName
jdbc:oracle:thin:@<TNSName>
Note: Support for TNSNames was added in the driver release 10.2.0.1

Oracle JDBC OCI Driver Format - require Oracle client software
jdbc:oracle:oci:@<database_name>

With the simple setup for his data source:
dataSource.url = jdbc:oracle:oci:@ADSBCPD or
dataSource.url = jdbc:oracle:thin:@AYSBDBS01:1621/ADSBCPD

The connection from his system to database was working pretty good.