Requirement: I have an Oracle database XE. I want to connect to the database using JDBC driver and query the EMPLOYEES table. I want to display the LAST_NAME of the employee having EMPLOYEE_ID=101.
The purpose of this post is to demonstrate how we can establish JDBC connection programmatically without using the wizard provided in JDeveloper.
Solution: For solution to the above requirement follow the steps below:
Step 1: Download the Oracle JDBC Driver (ojdbc6.jar) from the following URL:
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
Step 2: Open JDeveloper and create a Java Desktop Application. Give the application name as “DBDemo“. Give the Project Name as “JDBCDemo“.
Step 3: Add ojdbc6.jar in the Libraries and Classpath of the “JDBCDemo’. To add the ojdbc6.jar right click on the JDBCDemo > Select Project Properties > Libraries and Classpath > Add JAR/Directory (Browse and add the ojdbc6.jar).
Step 4: Create a new Java class EmpDetail. Write the below Java code
Thus, when we compile and run the Java code we get the below output:
Last name of Employee 101 is : Kochhar
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
441 total views, 2 views today