The problem is that you have implemented the doGet method. From a HTML form using the
POST METHOD you need to replace the default doPost method from HttpServlet. This is
definitely the cause of the error that you reported below.
As to your query, there does appear to be a problem here too...
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
It should be something more like this...
INSERT INTO LHS_WEB_Survey
(Q1, Q2, DO_BEST, NEEDS_IMPROVE, OTHER_COMMENT, F_NAME, L_NAME)
VALUES (theQ1, theQ2, doBest, theComment1, theComment2, fname, lname);
the problems that I have fixed here are...
1. Brackets around the field list
2. End Bracket at the end of the value list
3. Match the number of values to the number of fields
4. Keyword FROM does not belong in an insert query _unless_ you are populating
one table from another table. In that case though the value list would be
be replaced by a select query, ie.
'select field_list from table_name where condition_list'
-----Original Message-----
From: Jayakumar Mounagurusamy [mailto:[EMAIL PROTECTED]]
Sent: Sunday, 27 February 2000 11:32
To: [EMAIL PROTECTED]
Subject: Re: SERVLET - inserting databse values from an HTML form.
hello!
I understand that u did not get the values from the HTML Form. First u got
to get the data from the form and insert into the sql statement why don't u
use createStatament() instead preparedStatement. Please reply to my personal
email if u r interested
Jayakumar
>From: "Lambert, Stephen : CO IR" <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: SERVLET - inserting databse values from an HTML form.
>Date: Thu, 24 Feb 2000 10:23:09 -0800
>
>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
______________________________________________________
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
EOM
NOTICE - This message contains information intended only for the use of the addressee
named above. It may also be confidential and/or privileged. If you are not the
intended recipient of this message you are hereby notified that you must not
disseminate, copy or take any action in reliance on it. If you have received this
message in error please notify [EMAIL PROTECTED]
___________________________________________________________________________
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