0

I have a Java program that connects to an external Microsoft Access database. The following shows code in a databasehandler class, that is used to connect to the database.

static public int makeConnectionToFIREPLACEDB() {
    try {
        // Make connection to Database
        connectionToFIREPLACEDB = DriverManager.getConnection("jdbc:odbc:FIREPLACE");
    } catch (SQLException exception) {       
        return (-1);    // Return back with -1 if there is a problem 
                        // making a connection
    }
    return (0);   // Return back with 0 if connection is made to database        
} // end

The follow shows part of the code for a class of the program that uses the external database. This class views data from the database (which is at the bottom of the code but isn't necessary for this question). When I try to access the database I get the following error: Unable to connect to the database table FIREPLACE.

if ( DataBaseHandler.loadDriver() == -1 ) {
    JOptionPane.showMessageDialog (frame, "Problem loading the JDBC/ODBC driver.");
// Check to see if we can connect to the database table
} else if ( DataBaseHandler.makeConnectionToFIREPLACEDB() == -1 ) {
    JOptionPane.showMessageDialog (frame, "Unable to connect to the database table FIREPLACE");
} else { // Search for all the fireplaces
         // ...show data

So I cannot connected too external database, any help would be much appreciated.

Update: get the following error:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
Tom
  • 41
  • 6
  • Add this line `exception.printStackTrace();`immediately after `catch (SQLException exception) {`. This will print exception details to the console. Paste those details in the question. That will help us identify your problem. – Balkrishna Rawool Jun 18 '15 at 21:24
  • java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application – Tom Jun 18 '15 at 21:37
  • Look at the answers of this question: http://stackoverflow.com/questions/8895823/the-specified-dsn-contains-an-architecture-mismatch-between-the-driver-and-appli – Balkrishna Rawool Jun 18 '15 at 21:41
  • You are likely using trying to access a 64bit database with a 32bit driver or visa versa. I would recommend against using the JDBC/odbc bridge and use a dedicated JDBC driver instead – MadProgrammer Jun 18 '15 at 21:48
  • Probably easier to use `boolean` return types instead of numbers. `return false;` would indicate failure and `return true;` would indicate success. Going a bit further you could not return anything but instead throw an exception if it fails to connect, allowing the caller to catch it and deal with it in some way (even if it's just to present the `JOptionPane` – SnakeDoc Jun 18 '15 at 22:35

0 Answers0