| Author |
Facing Problems with DataBase
|
Knaresh Gupta
Greenhorn
Joined: Nov 22, 2008
Posts: 5
|
|
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 dbc dsn","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 dbc dsn","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 ]
|
 |
rahulash sharma
Greenhorn
Joined: Jan 05, 2009
Posts: 15
|
|
Add semicolon(;) in Your query in second file and another thing you should remember always close statement first and then connection
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Here, on first time i am used type1(sun.jdbc.odbc.JdbcOdbcDriver) driver on that time i am successfully fetching the records from DB.
Why are you using the JDBC-ODBC bridge? It has well documentated issues and Oracle supplies their own JDBC drivers.
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.
Type 2? Again, why? What Oracle specific native functionality do you require that prevents you from using the type 4 thin driver?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
 |
|
|
subject: Facing Problems with DataBase
|
|
|