
sir i am trying to connect the jsp with oracle connectivity ,but i am facing some prblems please help me.

1)Import the packages:
<%@ page import="java.sql.*"%> <%@ page import oracle.sql.*"%> <%@ page import="oracle.jdbc.driver.*"%>
2)Load the oracle driver:
Class.forName("oracle.jdbc.driver.OracleDriver");
3) Connect to database:
a) If you are using oracle oci driver,you have to use:
Connection connection= DriverManager.getConnection("jdbc:oracle:oci8:
@oracle.world", "root", "root");
where oracle.world is the TNS NAMES entry and root is the username and password.
b) If you are using oracle thin driver,you have to use:
Connection connection= DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:roseindia",
"root", "root");
where localhost is the host,3306 is the port, roseindia is the database and root is the username and password.
4)Querying the database:
a)create statement:
Statement st = connection.createStatement();
b)write query and execute the query:
ResultSet rs = st.executeQuery("SELECT * from data");
5) Close the statement,resultset and connection:
rs.close(); st.close(); connection.close();
Example:
<%@ page import="java.sql.*"%>
<%@ page import oracle.sql.*"%>
<%@ page import="oracle.jdbc.driver.*"%>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle", "rose", "rose");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("Select * from data");
while(rs.next(){
String name=rs.getString("name");
String add=rs.getString("address");
out.println(name+" "+add);
}
rs.slose();
st.close();
connection.close();
}
catch (Exception ex) {}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.