Introduction
This document deals with the JSP connectivity with Oracle.This also exemplifies adding,updating, deleting and retrieving records from database(Oracle) through JSP.
Prerequisites
- Tomcat Server.
- Oracle Client.
- Oracle Server.
Target Readers : All
Getting Started
Copy a jar file class12.jar from Oralce_root->jdbc->lib->class12.jar
to Tomcat Server in Tomcat_root->common->lib.
Database Connectivity
| <% try{ Class.forName(”oracle.jdbc.driver.OracleDriver”).newInstance(); //Creating the connection object con.close(); |
Note:
172.24.205.62 -> IP Address of Oracle Server.
1521 -> Port Number.
infosys -> Host String.
Uname -> UserName.
Pwd -> Password.
Adding a Record
| <% try{ Class.forName(”oracle.jdbc.driver.OracleDriver”).newInstance(); //Creating the connection object PreparedStatement stmt = con.prepareStatement(”insert into Table_Name values(?,?,?)”); stmt.executeUpdate(); con.close(); |
Where column1,column2,column3 can be static values or can be taken from the previous page by establishing session.
Deleting a Record
| <% try{ Class.forName(”oracle.jdbc.driver.OracleDriver”).newInstance(); //Creating the connection object PreparedStatement stmt = con.prepareStatement(”delete from Table_Name where EmpName=’XYZ’”); con.close(); |
Updating a Record
| <% try{ Class.forName(”oracle.jdbc.driver.OracleDriver”).newInstance(); //Creating the connection object PreparedStatement stmt = con.prepareStatement(”update Table_Name set Designation=’Software Engineer’ where EmpName=’XYZ’”); con.close(); |
Retrieving a Record
| <% String empName=”"; int empNumber=0; String empDesignation=”"; try{ //Creating the connection object PreparedStatement stmt = con.prepareStatement(”select * from Table_Name”); while(rs.next()) out.println(empName); con.close(); |
Tags: coding tips, Jsp - Oracle Connectivity, JSP FAQ, oracle, technical FAQ, technical tips