hi,
please assume it is already connected to the access database( it is connected) since i could get all the data out and put them onto a JTable.
What is wrong now ... is that i am trying to insert new data to the access db and i got
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 12.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at DataHolder.addRecord(DataHolder.java:84)
at Screen.actionPerformed(Screen.java:261)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
please see part of my codes here:
//////////// in my database class ///////////////
public void addRecord(int id, String fn, String ln, String phone, String add, String city, String st, String zip, int age, String sex, double hr, double hrs)
{
try
{
String query = " INSERT INTO employees(id, firstName, lastName, phone, address, city, state, zip, age, sex, hourlyRate, hours) " +
"VALUES (id, fn, ln, phone, add, city, st, zip, age, sex, hr, hrs) ";
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
}
catch(SQLException sqlex)
{
sqlex.printStackTrace();
}
}// end addRecord
///////////////// let's say in the main class /////////
else if(e.getSource() == saveButton)
{
int id = new Integer(idField.getText());
String fn = fnField.getText();
String ln = lnField.getText();
String phone = phoneField.getText();
String add = addField.getText();
String city= cityField.getText();
String state = stateField.getText();
String zip = zipField.getText();
String sex = sexField.getText();
int age = new Integer(ageField.getText());
double hourly = new Double(hourlyField.getText());
double hours = new Double(hoursField.getText());
dh.addRecord(id, fn, ln, phone, add, city, state, zip, age, sex, hourly, hours);
}
i double and triple checked my access that all the column names are matched to insert() ...
thanks very much.