Hello, Thanks for the help! The following code works:
addSQL="INSERT INTO location (location, region, addressLine1, addressLine2, addressLine3, addressLine4, addressLine5, addressLine6, addressLine7, addressLine8, addressLine9, addressLine10, phoneNumber, faxNumber, manager1, manager2, director, url, chart) 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); addLocation.setString(18, website); addLocation.setString(19, chart); addLocation.executeUpdate(); addLocation.close(); Thank you!! -Tifany --- Daniel Jaffa <[EMAIL PROTECTED]> wrote: > This is more a database question and not much of a > jsp question > but here is the answer > > addSQL="INSERT INTO location (put all the database > column names, minus the > field that is auto_increment. Comma Delimented) > VALUES (?, ?, ?, ?, ?, ?,?, > ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; > > You should always name the fields that you are > adding. > > ----Original Message Follows---- > From: "Tiffany C." <[EMAIL PROTECTED]> > 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