1 Reply Latest reply on Jun 3, 2013 10:25 AM by m p

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file

    m p Newbie

      Background:

      I am developing in Eclipse and using Struts 2 framework to build and deploy .war file to JBoss. 4.2.3GA

       

      There is an action class that I am using to insert a user into a database table - pretty simple stuff

       

      I get the following exception for executeUpdate() method.

       

      DEBUG com.opensymphony.xwork2.DefaultActionInvocation.debug:68 - Executing action method = execute

      [STDOUT] >>>>>>>>>>insert into catNav.USERS values('mm', 'pp', 88, 'mm.pp@yahoo.com');

      [STDOUT] java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file 'C:\java\jboss-4.2.3.GA\bin\catNav.mdb'.

       

      I am provide the full path to the database .mdb file but the exception is referring to file in jboss folder, which is does no exist.  I am struggling to find a solution to resolve this.  The path, using either \\ or / file separators is validated as an exception occurs if invalid path is defined.

       

      The code is below; I have the same code in a standalone Java program that executes successfully (I verify row was added)  .... but fails when running on JBoss

       

      public String execute() throws Exception {
        
        //call Service class to store personBean's state in database
        final String dbName = "catNav";

        Connection con = null; // The connection to the database.
       
        Statement stmt = null;
       
        // The following code can throw errors, so they must be caught.
        try{

         // First, tell Java what driver to use and where to find it.
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        
         // Next, create a connection to your data source.
         // Specify that you are using the ODBC-JDBC Bridge.
         // And specify the data source name from ODBC.
         String database =
                   "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Users/mp/Documents/Work/JDBC/catNav.mdb;";
        
         con = DriverManager.getConnection(database, "", "");

         /* also tried:
         con = DriverManager.getConnection("jdbc:odbc:catNavDB");
         */
        
         // Create an SQL statement.
         stmt = con.createStatement();
       
         // Execute some SQL to create a table in your database.
         // If the table already exists, an exception is thrown!
         String sqlSt = "insert into " + dbName +
           ".USERS " +
           "values('" + personBean.getFirstName() + "', " +  // FIRST_NAME
           "'" + personBean.getLastName() + "', " +          // LAST_NAME
           personBean.getAge() + ", " +                      // AGE
           "'" + personBean.getEmail() + "'); "  ;           // EMAIL
        
         // display SQL statment
         System.out.println (">>>>>>>>>>" + sqlSt );
        
         stmt.executeUpdate( sqlSt); 
        
         }
         // Catch any exceptions that are thrown.
         etc.