I'm trying to connect to a database made by MS Access using Java, but I cannot seem to manage. I am using ODBC and I'm getting this exception:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
My Java:
package javaapplication2;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author Owner
*/
public class JavaApplication2 {
/**
* @param args the command line arguments
*
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL = new String("jdbc:odbc:myDatabase");
System.out.println(sourceURL);
Connection dbConnection = DriverManager.getConnection(sourceURL,"admin","");
Statement myStmt = dbConnection.createStatement();
String query = "INSERT INTO People(ID, Name, Surname, Age, Contact, Location, Course) VALUES"
+ " (1007, 'Elroy', 'Smith', '33', 21366688, 'Somewhere', 'somecourse')";
myStmt.executeUpdate(query);
ResultSet results = myStmt.executeQuery("SELECT * FROM People");
while(results.next())
{
System.out.print(results.getString(1));
System.out.print(results.getString(2));
System.out.print(results.getString(3));
System.out.println(results.getString(4));
}
results.close();
}
catch(ClassNotFoundException cnfe)
{
System.out.println(cnfe);
}
catch(SQLException sqle)
{
System.out.println(sqle);
}
}
}
I had a great deal of trouble linking to MySQL from a 64 bit laptop, running Windows 7, using MS Access 2010. I found the previous article very helpful, but still could not connect using odbc 3.5.1. As I had previously linked a 32 bit machine using Connector/ODBC 5.1.13, I downloaded that version and set it up using the instructions above. Success. The answer seems to be to try different versions of Connector.odbc.
To solve this problem first make sure that your java software should be 32bit version if it is 64 bit version clearly it will show the mismatch error so try to re-install 32bit of java version And execute the java program in the command of
c:\windows\sysWOW64\odbcad32.exe
(easiest to copy and paste into run dialog) that's enough your program definitely workI ran into this problem when upgrading to a windows 7 server with some legacy CLASP applications. Trying to run a 32bit application on a 64 bit machine.
Try setting the application pools 32bit compatibility to True and/or create dsn's in 32 and 64 bit.
Open the odbc datasource window in both versions from the run box. C:\Windows\SysWOW64\odbcad32.exe C:\Windows\system32\odbcad32.exe
You get this exact same error when trying to connect to a MySQL database from MS-Access when the bit version (32 vs 64) of Access doesn't match
For those of you trying to connect MS-Access to MySQL on a 64 bit Windows system, I went through sheer torture trying to get it to work with both MS-Access 2010 and MS-Access 2013. Finally got it working, and here are the lessons I've learned along the way:
I bought a new Windows 7, 64 bit laptop, and I have an app which relies on MS-Access using MySQL tables.
I installed the latest version of MySQL, 5.6, using the All In One package install. This allows you to install both the database and ODBC drivers all at once. That's nice, but the ODBC driver it installs seems to be the 64 bit one, so it will not work with 32 bit MS-Access. It also seems a little buggy - not for sure on that one. When you Add a new DSN in the ODBC Manager, this driver appears as "Microsoft ODBC For Oracle". I could not get this one to work. I had to install the 32 bit one, discussed below.
I had previously installed Office 2013, which I assumed was 64 bit. But upon checking the version (File, Account, About Access), I see that it is 32 bit. Both Access 2010 and 2013 are most commonly sold as 32-bit versions.
My machine is a 64 bit machine. So by default, when you go to set up your DSN's for MS-Access, and go in the usual way into the ODBC Manager via Control Panel, Administrative Options, you get the 64 bit ODBC manager. You have no way of knowing that! You just can't tell. This is a huge gotcha!! It is impossible to set up a DSN from there and have it successfully connect to MS Access 32 bit. You will get the dreaded error:
You must download and install the 32 bit ODBC driver from MySQL. I used version 3.5.1
http://dev.mysql.com/downloads/connector/odbc/3.51.html
You must tell the ODBC Manager in Control Panel to take a hike and must instead explicitly invoke the 32 bit ODBC Manager with this command executed at the Start, Command prompt:
I created a shortcut to this on my desktop. From here, build your DSN with this manager. Important point: BUILD THEM AS SYSTEM DSNS, NOT USER DSNS! This tripped me up for awhile.
By the way, the 64 bit version of the ODBC Manager can also be run explicitly as:
Once you've installed the 32-bit ODBC Driver from MySql, when you click Add in the ODBC Manager you will see 2 drivers listed. Choose "MySQL ODBC 5.2 ANSI Driver". I did not try the UNICODE driver.
That does it. Once you have defined your DSN's in the 32 bit ODBC manager, you can connect to MySQL in the usual way from within Access - External Data, ODBC Database, Link to the Database, select Machine Data Source, and the DSN you created to your MySQL database will be there.
I did encounter this problem. This is due to you computer architecture and the database architecture you are using.
If you're using 32 bits operating system then everything works well because you can only install 32 bits software. Problem comes when you're using the 64 bits operating system.
In order to solve this problem is simple - I took long time to discover this issue.
You're unable to access your database because your 64 bits JVM is not the same as 32 bit JVM.
To add your database into your system 1. Control Panel 2. Administrator Tools 3. Data Source (ODBC) right click on it change the target to \sysWOW64\odbcad32.exe change the start in to r%\SysWOW64
Then you should be able to run. Inform me if you have any problem with this.
Thank you!
To solve this problem first make sure that your java software should be 32bit version if it is 64 bit version clearly it will show the mismatch error so try to re-install 32bit of java version And execute the java program in the command of c:\windows\sysWOW64\odbcad32.exe (easiest to copy and paste into run dialog) that's enough your program definitely work