Hi lambert,
probably i think the mistake u made is construction of prepared
statement and setting values to the prepared statement
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");
chnage the above statement to the following
PreparedStatement stat = conn.prepareStatement( "INSERT INTO
LHS_WEB_Survey (Q1, Q2, DO_BEST, NEEDS_IMPROVE, F_NAME, L_NAME FROM ) " +
"VALUES ( ?, ?, ?, ?, ?, ?);
then add the following lines
stat.setString(1,getParameter("theQ1"));
stat.setString(2,getParameter("theQ2"));
stat.setString(3,getParameter("theComment1"));
stat.setString(4,getParameter("theComment2"));
stat.setString(5,getParameter("fname"));
stat.setString(6,getParameter("lname"));
then execuete the query using
stat.executeQuery();
it will work. kindly refer the servlet documentation how to get parmeters
from the form posted i think it is getParameter( String aName) method where
aName = form element Name. if i'm wrong bear with me
Regards,
R.Karunanithi,
Software Engineer
Arkin Systems Pvt. Ltd
Chennai
India
>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