• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Facing Problems with DataBase

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add semicolon(;) in Your query in second file and another thing you should remember always close statement first and then connection

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Don't MAKE me come back there with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic