u have 19 question mark, but u set up to 20, thats y give u error.
use INSERT INTO <table name> (column name1 column name2...) VALUES (?, ?,
...)
don't include the auto primarly key generation column in the INSERT
statement.


----- Original Message -----
From: "Tiffany C." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 07, 2002 3:18 PM
Subject: SQL insert with preparedStatement


> Hello,
>
> I'm trying to Insert a new row into a MySQL database
> using a preparedStatement.  However one of the fields
> in the database is an auto_increment primary key.  I
> want to insert the all other fields into the database
> and let the database enter the auto_increment primary
> key.  How do I do this?
>
> I currently have:
>
> String addSQL="";
> addSQL="INSERT INTO location VALUES (?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
> PreparedStatement addLocation =
> conn.prepareStatement(addSQL);
>
> addLocation.setString(1, locationName);
> addLocation.setString(2, region);
> addLocation.setString(3, address1);
> addLocation.setString(4, address2);
> addLocation.setString(5, address3);
> addLocation.setString(6, address4);
> addLocation.setString(7, address5);
> addLocation.setString(8, address6);
> addLocation.setString(9, address7);
> addLocation.setString(10, address8);
> addLocation.setString(11, address9);
> addLocation.setString(12, address10);
> addLocation.setString(13, phoneNumber);
> addLocation.setString(14, faxNumber);
> addLocation.setString(15, manager1);
> addLocation.setString(16, manager2);
> addLocation.setString(17, director);
>
> //18 is the auto_increment Primary Key
>
> addLocation.setString(19, website);
> addLocation.setString(20, chart);
> addLocation.executeUpdate();
> addLocation.close();
>
> And it results in
> java.lang.ArrayIndexOutOfBoundsException
>
> How can I make this work?
>
> Sincerely,
> Tiffany
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/
>
>
===========================================================================
> 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://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com

===========================================================================
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://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to