Hai Stephen!
Insert command will not return any Resultset. it will return only an integer
which says the number of insertion. So in this case you have to use either
executeUpdate or execute statement
Jayakumar
>From: Pradeep Shekade <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: SERVLET - inserting databse values from an HTML form.
>Date: Tue, 29 Feb 2000 11:05:05 +0530
>
>Dear Stephen,
>
>This cannot work.
>
>The protocol you are using is GET. There should be statements in your
>program to
>get the values from URL string. Once you get the values then you can pass
>them
>to the insert statement.
>
>You will have to use the methods getParameter, getParameterNames and
>getParameterValues of the request object in order to access the values of
>theQ1, theQ2, theComment1, thecomment2, fname, lname. Once you get these
>values
>you will have to create a SQL string with these values in place and then
>pass
>this string as a parameter to prepareStatement().
>
>Hope this suffices.
>
>Regards,
>
>Pradeep Shekade
>
>
>
>"Lambert, Stephen : CO IR" wrote:
>
> > I have a working servlet that can query my Oracle database and display
>the
> > results to an HTML page(Hooray!).
> >
> > The second phase of this servlet is to insert data into the Oracle
>database
> > from an HTML form using the POST METHOD.
> > The HTML FORM names are:(theQ1, theQ2, theComment1, thecomment2, fname,
> > lname).
> >
> > Can someone please correct my java/sql syntax or point me to an actual
> > working sample code that shows how to insert HTML data into an Oracle
> > database.
> >
> > My servlet "JdbcServlet3" is listed below and will compile without
>errors.
> > However, when I try to POST the HTML FORM, I recieve the following
>error:
> > Bad Request
> > Your browser sent a request that this server could not understand.
> >
> >
>****************************************************************************
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import java.io.*;
> > import java.sql.*;
> >
> > /**
> > * JdbcServlet writes Legacy's Web Survey information to a JDBC database
> > * from a HTML form.
> > *
> > * @author Stephen B. Lambert
> > * @version 0.1a, 02/21/2000
> > */
> > public class JdbcServlet3 extends HttpServlet
> > implements SingleThreadModel {
> >
> > private Connection conn;
> > private void dbConnect() throws SQLException {
> >
> > DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
> > conn = DriverManager.getConnection
> > ("jdbc:oracle:thin:@w121c20.legacyhs:1521:FIRST",
> > "slambert", "password");
> > }
> >
> > /**
> > * doGet method is called in response to a GET request
> > */
> > public void doGet(HttpServletRequest request,
> > HttpServletResponse response) throws ServletException,
> > IOException
> > {
> > PrintWriter out = response.getWriter();
> > try
> >
> > {
> > response.setContentType("text/html"); //returns HTML
> >
> > //get handle to output stream
> > // PrintWriter out = response.getWriter();
> >
> > //create statement
> > dbConnect();
> > PreparedStatement stat = conn.prepareStatement( "INSERT INTO
> > LHS_WEB_Survey Q1, Q2, DO_BEST, NEEDS_IMPROVE, F_NAME, L_NAME FROM " +
> > "LHS_WEB_Survey" +
> > "VALUES ( theQ1, theQ2, theQ3, theComment1, theComment2, fname,
> > lname");
> >
> > //query database for result set
> > ResultSet survey = stat.executeQuery();
> > //generate HTML document to return to client
> > out.println("<HTML>");
> > out.println("<HEAD><TITLE>Survey List</TITLE></HEAD>");
> > out.println("<BODY>");
> > out.println("<H2>Survey List</H2>");
> > out.println("<TABLE BORDER=1>"); //create an HTML table
> > out.println("<TH>Satisfaction</TH>");
> > out.println("<TH>Parking</TH>");
> > out.println("<TH>Did Best?</TH>");
> > out.println("<TH>Needed Improvement</TH>");
> > out.println("<TH>First Name</TH>");
> > out.println("<TH>Last Name</TH></TR>");
> >
> > while (survey.next()) //iterate through all records
> > {
> > //add a table row for each record
> > out.println("<TR><TD>" +
> > survey.getString("q1")+ "</TD><TD>" +
> > survey.getString("q2") + "</TD><TD>" +
> > survey.getString("DO_BEST") + "</TD><TD>" +
> > survey.getString("NEEDS_IMPROVE") + "</TD><TD>" +
> > survey.getString("F_NAME") + "</TD><TD>" +
> > survey.getString("L_NAME") + "</TD></TR>");
> > }
> >
> > out.println("</TABLE>");
> > out.println("</BODY></HTML>");
> > }
> > catch (Exception e)
> > {
> > out.println(e.toString());
> >
> > }
> > out.close();
> > }
> >
> > /**
> > * Tells the server about this servlet
> > */
> > public String getServletInfo()
> > {
> > return "Sample JDBC servlet";
> > }
> > }
> >
> >
>***************************************************************************
> > Thank you!
> > Stephen.
> >
> >
>___________________________________________________________________________
> > 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
>
>___________________________________________________________________________
>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 Email 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