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:
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.
Thanks & Regards,
343 total views, 1 views today