Have you __realy__ understood what `PreparedStatement' does ?

Your SQL command looks flawed because if it missing the insertion token `?'
for example

     insert into employee_records
     values ( er_first_name, er_last_name, er_no, er_payroll_no )
     ( ?, ?, ?, ? )


Also you are using `PreparedStatement.executeQuery()' which is for querying
in to the database (`SELECT * FROM'), whereas you want to do an
update of the database (`INSERT INTO ... ' )

1) Read The Fine Manual (RTFM)  on JDBC or get decent book on it!

2) Remove all the JDBC code from the JSP and put it in side a Java Bean

--
Peter Pilgrim
G.O.A.T
                    "the Greatest Of All Time"



---------------------------------------- Message History 
----------------------------------------


From: sufi malak <[EMAIL PROTECTED]>@java.sun.com> on 22/02/2001 18:36


I am sorry I don't know if this is an off topic.
The employee table has exactly 11 columns, and this is my jsp code :

<%@page language="java" import="java.sql.*"%>
<%@ include file="Connections/connCompass.jsp" %>

<%
String  photo = (String)request.getParameter("txtImageURL");
String  employee_last= (String)request.getParameter("txtLastName");
String  employee_first = (String)request.getParameter("txtFirstName");
String  employee_id = (String)request.getParameter("txtId");
String  phone = (String)request.getParameter("txtPhone");
String  reward_date = (String)request.getParameter("txtDate");
String  department = (String)request.getParameter("txtDept");
String  employee_extension = (String)request.getParameter("txtExt");
String  email = (String)request.getParameter("txtEmail");
String  nominee_info = (String)request.getParameter("txtNotes");
String  nominated_by = (String)request.getParameter("txtNominatedby");

%>
<%
System.out.println("test zero....");
Driver DriverResults =
(Driver)Class.forName(MM_connCompass_DRIVER).newInstance();
Connection ConnResults =
DriverManager.getConnection(MM_connCompass_STRING,MM_connCompass_USERNAME,MM_connCompass_PASSWORD);
PreparedStatement StatementResults;
String stmt = "insert into employee VALUES(employee_id, employee_first,
employee_last, nominated_by, photo, employee_extension, department,
nominee_info, phone, email, reward_date)";
StatementResults = ConnResults.prepareStatement(stmt);
if (!((photo == null) | (employee_last == null) | (employee_first == null) |
(employee_id  == null) | (phone  == null) |
   (department == null) | (reward_date  == null) | (employee_extension ==
null) | (email == null) | (nominee_info == null) | ( nominated_by == null)
))
{
StatementResults.executeQuery();
response.sendRedirect("insertok.jsp");
System.out.println("test one....");
}
%>

But when I run it, I got this error,( is this a Microsoft Access error?):
A Servlet Exception Has Occurred
Exception Report:
javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver]
Too few parameters. Expected 11.
        at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:481)

--<CUT>--



--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to