java.sql.SQLException: Invalid column index
516313Jan 25 2007 — edited Jan 30 2007hello everyone,
I am trying to insert data into a table and I keep getting this exception. Could someone kindly please let me know where I am going wrong? Thanks
this is the code I use the extract data from the form:
private void submitButton_actionPerformed(ActionEvent e) throws SQLException,
IllegalArgumentException
{
MySQL mySQL = new MySQL();
SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy" );
String studId = studIdText.getText();
String schLev = schLevelText.getText();
String enqDate = enqDateText.getText();
//Date enqDt = (Date)sdf.parse( enqDate );
Date enqDt;
enqDt = Date.valueOf(enqDate);
String lName = lNameText.getText();
String fName = fNameText.getText();
String mInitial = mInitialText.getText();
String dob = dobText.getText();
//Date dobDt = (Date)sdf.parse( dob );
Date dobDt;
dobDt = Date.valueOf(dob);
String addr1 = addrLine1Text.getText();
String addr2 = addrLine2Text.getText();
String city = cityText.getText();
String phNum = phoneText.getText();
String contact = contactText.getText();
//java.util.Date today = new java.util.Date();
Calendar cal = new GregorianCalendar(2001, 0, 1);
//Date today = new Date(Calendar.getTime());
Date createdDate = new Date(cal.getTime().getTime());
//Date createdDate = today.getTime();
String createdBy = "";
mySQL.insertEnquiry(studId, schLev, enqDt, lName, fName, mInitial, dobDt,
addr1, addr2, city, phNum, contact, createdDate, createdBy);
}
}
this is the "database" part :
public static void insertEnquiry(String studId, String schLevCd,
Date enqDate, String lName, String fName, String mInitial,
Date dob, String addr1, String addr2, String city, String phone,
String contact, Date sqlDate, String createdBy) throws SQLException
{
try
{
myConnection();
Connection conn = DriverManager.getConnection
(database, usrname, pssword);
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO enquiries VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
try {
stmt.setString(1, studId);
stmt.setString(2, schLevCd);
stmt.setDate(3, enqDate);
stmt.setString(4, lName);
stmt.setString(5, fName);
stmt.setString(6, mInitial);
stmt.setDate(7, dob);
stmt.setString(8, addr1);
stmt.setString(9, addr2);
stmt.setString(10, city);
stmt.setString(11, phone);
stmt.setString(12, contact);
stmt.setDate(13, sqlDate);
stmt.setString(14, createdBy);
stmt.execute();
}
catch(SQLException excep) {
System.out.println("Could not add Enquiry: " + excep);
excep.printStackTrace();
}
}
catch (SQLException excon) {
System.out.println(excon);
}
}