For connecting java application with the oracle database, we need to follow the above steps. Here I am using Oracle10g as the database. So we need to know following information for the oracle database:
Let’s see an example to retrieve all the records of employee table. So we have to first create a table in oracle database, then inserting some records, then writing a jdbc application to retrieve records from oracle database.
//Creating table create table employee ( id number(10), name varchar2(40), sal number(7) ); For inserting a record, the required sql statement is: insert into employee values(101,’Rosalin’,15000);
JdbcExample1.java import java.sql.*; class JdbcExample1 { public static void main(String[] args) throws Exception { Class.forName(“oracle.jdbc.driver.OracleDriver”); Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@ localhost:1521:xe”, “system”, “password”); Statement st=con.createStatement( ); ResultSet rs = rs.executeQuery(“select * from employee”); while(rs.next( )) { System.out.println(rs.getInt(1)+” “+rs.getString(2)+” “+rs.getInt(3)); } con.close( ); } }
101 Rosalin 15000
Note:
To connect java application with the Oracle database, ojdbc14.jar file is required to be loaded.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc