This quick start guide helps Java developers to successfully establish a connection to the Oracle Database. Follow these easy steps to get started:
Step 1: Prerequisites
Step 2. Setting up the Connect String
Modify the Java code and Update the Database Credentials of the database that you have access to.
(a) Change the connect string to use your database's username, password, host name/IP address, database service name, and port number,
Example: DB_URL =
DB_USER = "hr" and DB_PASSWORD ="hr"
(b) Sample code uses the HR.EMPLOYEES table. If you do not have the HR schema in your database, modify the tables and columns in the code to use a table that you do have access to or even use a simple query "Select sysdate from dual" for testing purposes.
Step 3. Build and Run a Sample Java Program
Compile the Java code
javac -classpath ./pb/ojdbc8.jar:. DataSourceSample.java
javac -classpath ./pb/ojdbc8.jar:./pb/ucp.jar:. UCPSample.java
Run the sample Java program
java -classpath ./pb/ojdbc8.jar:. DataSourceSample
java -classpath ./pb/ojdbc8.jar:./pb/ucp.jar:. UCPSample
1 If you have JDK7 or JDK6 then you must use ojdbc7.jar or ojdbc6.jar from 18.104.22.168 or 22.214.171.124. Use "java -version" to check the JDK version that you have installed. Use "java -jar -ojdbc8.jar" to check the JDBC driver version.