Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2007, 06:11 AM
Registered User
 
Join Date: Apr 2007
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.

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

            try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            // 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
            s.close(); 

            // close the Connection to let the database know we're done 
            con.close(); 



        }


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

               }   
         }
 
Old April 24th, 2007, 07:16 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
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.
http://www.javaskyline.com/learnjdbc.html
http://www.freeprogrammingresources.com/jdbc.html

Regards,
Rakesh





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





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