Hi Friends. I am facing Microsoft ODBC Driver error at run time in my program. I am using window 7, jdk 7 and Ms Access 2007. I am using "jdbc:odbc:JdbcOdbcDriver". I am giving code and error message below. Please tell me solution of this problem

import java.sql.*;    

public class JdbcDMLEx2
{
   public static void main(String[] args)
        {

           try
           {           

         // load driver
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

          // define connection
          String url = "jdbc:odbc:personDSN";

          // establish connection

          Connection con = DriverManager.getConnection(url);

            // make query and place ? where values are 
            // to be inserted later

         String sql = "UPDATE persons SET address = ? WHERE name=?";

           // creating statement using connection object
           // and passing sql statement as parameter

             PreparedStatement pStmt = con.prepareStatement(sql);

          // assigning first command line argument value 

             String addVar = args[0];

          // assigning 2nd command line argument value 

            String nameVar = args[1];

          //setting first marked parameter(?)by using setString()
         // method to address

           pStmt.setString(1, addVar);

            //setting second marked parameter(?)by using setString()
         // method to name


          pStmt.setString(2, nameVar);


          //executing prepared statement
           int num = pStmt.executeUpdate();

        //   process the results of query
        // printing number of records affected

         System.out.println(num +"records updated");

         // step8: close the connection
            con.close();

          }
        catch(Exception sqlEx)

             {
               System.out.println(sqlEx);

             }

      }// end main

  } // end class

Following error is occuring at run time:

[Microsoft][ODBC Microsoft Access Driver] Too few parameters.expected 4.

Re: Driver error 80 80

Which line of the code is throwing that Exception?

Re: Driver error 80 80

Please check if there are invalid columns specified in the update statement. This is generally thrown in such a case.

Re: Driver error 80 80

Also, you need to find some more up to date sources of Java code!

classForName has been obsolete for many years now, so ignore any tutorial that uses it (Oracle's own tutorials are the only ones to trust - https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html )

More seriously the JDBC/ODBC link is obsolete, and is not present in current (1.8) Java versions. See https://www.daniweb.com/software-development/java/threads/497814/eclipse-odbc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.