Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2007, 06:11 AM
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 ( rs.next() ) // 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);

  #2 (permalink)  
Old April 24th, 2007, 07:16 AM
Friend of Wrox
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

I think you've missed few fundamentals.
  1. You forgot to pass the parameters to the inser statement.
  2. To read data from a table first we'll issue a select query and use execureQuery() method of the statement class which'll return the resultset object.

Try to go through some JDBC material.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a gridview control w/access database p3aul ASP.NET 1.0 and 1.1 Professional 0 October 2nd, 2007 06:14 PM
Database migration MS Access 2003 to MS SQL 2000 ayazhoda SQL Server 2000 3 April 23rd, 2007 11:38 AM
MS ACCESS UPDATING A SUBFORM FIELD bernieregans SQL Language 1 February 3rd, 2006 04:26 PM
updating yes/no field in MS Access database enigma82 Classic ASP Databases 2 May 6th, 2005 11:04 AM
Updating from no access database penta Access 12 October 27th, 2004 05:06 AM

All times are GMT -4. The time now is 01:51 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.