You can try with executeupdate or execute instead of
executeQuery.The executeQuery is used for executing
select statements.
You are using the preparedstatement class in this.If
you know the values already then then you can use the
normal statement class itself.
Statement st= con.createStatement();
st.executeUpdate("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");
ranga
--- JangHo Ki <[EMAIL PROTECTED]> wrote:
> Try executeUpdate() instead of executeQuery().
>
> JangHo Ki.
>
>
> On Thu, 24 Feb 2000 10:23:09 -0800 "Lambert, Stephen
> : CO IR"
> <[EMAIL PROTECTED]> writes:
> > 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
>
____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
___________________________________________________________________________
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