Hi Biren,
You r probably doing two mistakes one u have to use
stmt.executeQuery() instead of stmt.executeUpdate() which is generally only
for update statements. Secondly since u r using Oracle u must explicitly
commit the transactions by using conn.commit().
bye,
Jiger
>From: Biren Patnaik <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Help on a simple program
>Date: Mon, 8 May 2000 12:25:57 +0100
>
>Hi all,
>I have written a simple program,whose work is to add and delete a record
>from a database.After executing the html file,it is not showing any error
>message,infact it is showing "Done" in the status bar,but records are
>neither inserted nor deleted from the database.I m sending the full
>codes.Please check it and send me reply .I m waiting for reply.I m using
>JSWDK1.0.1. AND ORACLE.
>
>srvtimp.html
>
><html>
>
><head>
><meta http-equiv="Content-Type"
>content="text/html; charset=iso-8859-1">
><meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
><title></title>
></head>
>
><body background="http://net/srvt/vnet.jpg" text="#FF0000">
><script language="javascript">
>function check()
>{
>// alert("ok");
>}
>
></script>
>
><form name="form1" method="post"
>action="http://147.0.1.41:8080/servlet/srvtimp">
><input type="text" size="10" name="T1" value="">
><input type="text" size="10" name="T2" value="">
><input type="hidden" name="ad" value="">
><input type="submit" name="insert"
>onclick="document.form1.ad.value='add';">
><input type="submit" name="delete"
>onclick="document.form1.ad.value='del';">
></form>
></body>
></html>
>
>srvtimp.java
>
>import javax.servlet.*;
>import javax.servlet.http.*;
>import java.io.*;
>import java.sql.*;
>
>public class srvtimp extends HttpServlet
>{
>Connection conn = null;
>Statement stmt = null;
>ResultSet rst = null;
>PrintWriter out=null;
>ResultSetMetaData rdata=null;
>
>public void init() throws ServletException {
>
> try {
>
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>
>conn=DriverManager.getConnection("jdbc:odbc:prjct1","scott","tiger");
> } catch(ClassNotFoundException e) {
> System.out.println("CustSvc: Database driver could not be
>found.");
> System.out.println(e.toString());
> throw new UnavailableException(this, "Database driver class not
>found");
> } catch(SQLException e) {
> System.out.println("CustSvc: Error connecting to the database.");
> System.out.println(e.toString());
> throw new UnavailableException(this, "Cannot connect to the
>database");
> }
> }
>
>
>/*public void doGet(HttpServletRequest rqst, HttpServletResponse rsp)
>{
>try
>{
>doPost(rqst,rsp);
>}catch(Exception e){}
>}*/
>
>public void doPost(HttpServletRequest rqst, HttpServletResponse rsp)
>throws
>
>ServletException,IOException
>{
>try
>{
>String bT = rqst.getParameter("ad");
>String mT1 = rqst.getParameter("T1");
>String mT2 = rqst.getParameter("T2");
>
>if(bT == "add")
>{
>stmt = conn.createStatement();
>rsp.setContentType("text/html");
>stmt.executeUpdate("INSERT INTO EMP1 VALUES('" + mT1 +
> "','" + mT2 + "')");
>}
>if(bT == "del")
>{
>stmt = conn.createStatement();
>rsp.setContentType("text/html");
>stmt.executeUpdate("DELETE FROM EMP1 WHERE NAME = '" +mT1+ "'");
>}
>out.close();
>}
>catch (SQLException e) {
> rsp.sendError(rsp.SC_ACCEPTED, "The request has been accepted, but
>it failed to complete
>
>due to an error updating the database.");
> System.out.println(e.toString());
> return;
> }
> catch (NumberFormatException e) {
> rsp.sendError(rsp.SC_BAD_REQUEST, "At least one of the input fields
>is non-numeric. Please
>
>correct and try again.");
> System.out.println(e.toString());
> return;
> }
>
>
>catch(Exception e)
>{
>//out.println("<script
>language='javascript'>defaultStatus='Error';</script>");
>}
>}
>public void destroy()
>{
>try
>{
>conn.close();
>}
>catch(Exception e)
>{
>System.out.println("Emp: Database close Failed");
>System.out.println(e.toString());
>}
>}
>}
>Thanx in advance
>Biren
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html