Dear all,
I am facing the problems while i am connecting to the Oracle DB.
Here,
on first time i am used type1(sun.jdbc.odbc.JdbcOdbcDriver) driver on that time i am successfully fetching the records from DB. But i am not able to inserting the recording into DB. While inserting i am not getting any error on browser. Browser keep on showing the Current page itself.
On second way i am used type2(oracle.jdbc.driver.OracleDriver) driver this time i am not able to fetch the records and insert the records.
Here is the code
Code for fetching the records:
<%@ page import="java.sql.*,java.io.*" errorPage="ErrorDb.jsp"%>
<%! Connection con; %>
<%! Statement stmt; %>
<%! ResultSet rs; %>
<%!
public void jspInit()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:odsn","Naresh","kngerp");
stmt=con.createStatement();
rs=stmt.executeQuery("select * from student");
}
catch(Exception e){}
}
%>
<%
if(rs.next())
{
int sid=rs.getInt(1);
String sname=rs.getString(2);
String email=rs.getString(3);
String mobile=rs.getString(4);
out.println(sid);
out.println(sname);
out.println(email);
out.println(mobile);
}
%>
<%= con %>
<%!
public void jspDestroy()
{
try
{
con.close();
}
catch(Exception e){}
}
%>
Code For the inserting the records:
<%@ page import="javax.sql.*" %>
<%! Connection con;%>
<%! PreparesStatement pstmt;%>
<%!
public void jspInit()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:odsn","Naresh","kngerp");
Connection con = DBConn.getConn();
PreparedStatement pstmt = con.prepareStatement("INSERT INTO student VALUES (?,?,?,?)");
}
catch(Exception e){}
}
%>
<%
int sid=Integer.parseInt(request.getParameter("sid").trim());
String sname=request.getParameter("sname").trim();
String email=request.getParameter("email").trim();
String mobile=request.getParameter("mobile").trim();
pstmt.setInt(1, sid);
pstmt.setString(2, sname);
pstmt.setString(3, email);
pstmt.setString(4, mobile);
pstmt.executeUpdate();
%>
<b> Record Inserted SuccessFully.........</b>
<%!
public void jspDestroy()
{
try
{
con.close();
pstmt.close();
}
catch(exception e){}
}
%>
Regards,
Naresh Gupta
[ January 02, 2009: Message edited by: KNaresh Gupta ]