Results 1 to 7 of 7
  1. #1
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default JDBC ODBC SQLException

    Hello I am trying to connect to a data source with the ODBC Data Source Administrator but I am getting an error when I run.

    The error that I am getting is:

    Java Code:
    SQL Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application 0 IM014
    The code is:

    Java Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class CoalReporter {
    	public static void main(String[] args){
    		String data = "jdbc:odbc:WorldEnergy";
    		try{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			Connection conn = DriverManager.getConnection(
    					data,"","");
    			Statement st = conn.createStatement();
    			ResultSet rec = st.executeQuery(
    					"SELECT * "+
    					"FROM Coal "+
    					"WHERE "+
    					"(Country='"+args[0]+"') "+
    					"ORDER BY Year");
    			System.out.println("FIPS\tCOUNTRY\t\tYEAR\t"+
    					"ANTHRACITE PRODUCTION");
    			while(rec.next()){
    				System.out.println(rec.getString(1)+"\t"
    						+rec.getString(2)+"\t"
    						+rec.getString(3)+"\t"
    						+rec.getString(4));
    			}
    			st.close();
    		}catch(SQLException s){
    			System.out.println("SQL Error: "+s.toString()+" "
    					+s.getErrorCode()+" "+s.getSQLState());
    		}catch(Exception e){
    			System.out.println("Error: "+e.toString()
    					+e.getMessage());
    		}
    	}
    }
    I have used the odbcad.32 in this location: c:\windows\sysWOW64\odbcad32.exe as advised by this website: Managing Data Sources but I still get the error.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    4

    Default

    what database are you trying to connect?

  3. #3
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    I'm trying to connect to a MS access DB

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    4

    Default

    Check step 1 to 4. Have you done this steps?
    Accessing Ms Access Using Java


    You could also try to change your string data to something like this,
    Java Code:
    String databasePath = "D:\\myDatabase.mdb";
    String data = "jdbc:Odbc:Driver={Microsoft Access Driver (*.mdb)};"
            + "DBQ=" + databasePath;
    I am not familiar using MSAccess in java so this might NOT be the CORRECT WAY to connect it.

  5. #5
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    I checked that I had followed those steps and I have, I also tried the code you gave me, but I am still getting the same error. I am using 64 bit machine if that is any use to you.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Uhm, you have a "64 bit system", but do you have a "64 bit Office" or is your office suite 32 bit. According to the error (and the page you provided) it looks as though your office system is 32 bit and therefore you are using the 64 bit odbcad32.exe to configure a 32 bit driver and there fore are getting an error when using that configuration.

  7. #7
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    I did have 32 bit office 2007 installed but now I have got 64 bit office 2010 installed and everything is working just how it is meant to be.

    Thanks for your help, I'd have never figured that one out on my own.

Similar Threads

  1. jdbc-odbc cannot connect
    By ArneBassez in forum JDBC
    Replies: 4
    Last Post: 12-08-2010, 05:26 AM
  2. Replies: 1
    Last Post: 07-23-2010, 09:23 AM
  3. Replies: 1
    Last Post: 04-05-2010, 01:32 AM
  4. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 08:37 AM
  5. Using JDBC-ODBC bridge
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •