View Single Post
  #1 (permalink)  
Old April 24th, 2007, 06:11 AM
javlet javlet is offline
Registered User
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Updating MS Access database

I am getting an error when updating an MS Access database. Can someone please help.

The error is:

Error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few
parameters. Expected 9.

 private class Calculate implements ActionListener
            public void actionPerformed (ActionEvent ae)

            try {
            // set this to a MS Access DB you have on your machine
            String filename = "F:/Bernnie/java/referencingsys.mdb";
            String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";

            // add on to the end 
            database+= filename.trim() + ";DriverID=22;READONLY=true}"; 

            // now we can get the connection from the DriverManager
            Connection con = DriverManager.getConnection( database ,"",""); 

           // try and create a java.sql.Statement so we can run queries
           Statement s = con.createStatement();

           //Assign contents in textboxes to varialbles for the purpose of sending to database
           Surname = txtSurname.getText();
       Initials = txtInitials.getText();
           Year = txtYear.getText();
           Title = txtTitle.getText();
           Volume = txtVolume.getText();
           Edition = txtEdition.getText();
           Publisher = txtPublisher.getText();
           City =txtPubCity.getText();
           Pages = txtNo_of_Pages.getText();

           // Update the data from the table
           s.executeUpdate("insert into tblBook VALUES (Surname, Initials, Year, Title, Volume, Edition, Publisher, City, Pages)");

           // get any ResultSet that came from our query
           //ResultSet rs = s.getResultSet(); 
           //if (rs != null) // if rs == null, then there is no ResultSet to view
           //while ( ) // this will step through our data row-by-row

            /* the next line will get the first column in our current row's ResultSet 
            as a String ( getString( columnNumber) ) and output it to the screen */ 

            //System.out.println("Harvard Referencing Style: " + rs.getString("") );

            // close the Statement to let the database know we're done with it

            // close the Connection to let the database know we're done 


            catch (Exception e) {
            System.out.println("Error: " + e);