Tutorial
Tutorial
Instructions to follow:
6. Open any IDE tool to develop a java program to query the table created in the database.
7. The JAVA program is as follows:
import java.sql.DriverManager;
import java.sql.Connection;
import java.lang.Exception;
import java.sql.Statement;
import java.sql.ResultSet;
public class SelectEmployeeData {
public static void main(String args[]){
Connection con = null;
Statement statement = null;
String sql;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@10.1.67.153:1522:orclNew",
"username","password");
statement = con.createStatement();
sql = "Select * from Employee";
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
System.out.println("\nEmployee ID: "+resultSet.getString(1));
System.out.println("Employee Name: "+resultSet.getString(2));
System.out.println("Designation: "+resultSet.getString(3));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
8. Add the library called ojdbc8.jar in the created JAVA project.
9. Compile the JAVA file
10. Execute the JAVA file and verify the output.