Connect JDBC to MS Access

I want to link my MS access file with a Java GUI program, but I have a connection problem ....

I have Windows 7 64b and ms office 2007. When I opened the ODBC driver manager in the control panel, I did not find the driver for Microsoft Access (maybe when I started ODBC, I started working with 64-bit ODBC, now I think that 32 works -bit ODBC. I read this and I understood: "jdbc-odbc connection for window 7 of a 64-bit machine .. 1. Right-click the data source (ODBC) .. go to properties, change the following thing

target [% SystemRoot% \ SysWOW64 \ odbcad32.exe] start with: [% SystemRoot% \ System32]

press enter and continue as administrator source: source link ") Now, when I start in the ODBC control panel, I see the screenshoot driver

My program code (I tried two ways, but I have the same error):

public void Connect() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // String DatabaseFile = "D:java/Invertory.mdb"; // String DATABASE = // "jdbc:odbc:Driver=" // + "{Microsoft Access Driver (*.mdb, *.accdb)};" // + "DBQ=" + DatabaseFile;`enter code here` String DATABASE ="jdbc:odbc:Driver= Microsoft Access Driver (*.mdb, *.accdb);DBQ=Invertory.mdb"; CONEX = DriverManager.getConnection(DATABASE); } catch (Exception X) { X.printStackTrace(); //JOptionPane.showMessageDialog(null,e); } } 

Mistake

java.sql.SQLException: [Microsoft] [ODBC driver manager] Data source name not found and specified default driver not specified

+8
source share
9 answers

Use the UCanAccess JDBC Driver:

 Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<mdb or accdb file path>",user, password); for example: Connection conn=DriverManager.getConnection("jdbc:ucanaccess://c:/pippo.mdb"); 

So, for your example, this will be Connection conn=DriverManager.getConnection("jdbc:ucanaccess://"+path)

+10
source

If you are using a 64-bit version of Windows, you probably need to go this way

C: /Windows/SysWOW64/odbcad32.exe

Then I noticed that you are using the direct path instead of creating a new System DSN , your direct path is correct to the path to the access file, which you should give the full path as follows:

jdbc: odbc: Driver = Microsoft Access Driver (* .mdb, * .accdb); DBQ = path /to/Invertory.mdb "

To get the path, you probably need to use java.io.File , which has a method, returns the path of the abscess to the file, for example:

 import java.sql.*; public class TestConnection { Connection con ; Statement st ; ResultSet rs ; String db; public TestConnection (){ try{ String path = new java.io.File("Invertory.mdb").getAbsolutePath(); db ="JDBC:ODBC:Driver=Microsoft Access Driver (*.mdb, *.accdb); DBQ="+path; doConnection(); } catch(NullPointerException ex){ ex.printStackTrace(); } } public void doConnection(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection(db); st = con.createStatement(); rs = st.executeQuery("select * from Invertory"); while(rs.next()){ System.out.println(rs.getObject(1)); } }catch(SQLException | ClassNotFoundException ex){ System.out.println(ex.toString()); } } public static void main(String...argS){ new TestConnection(); } } 
+2
source

I answered a similar question, enter the link below .

Mostly at this time:

  • You can connect to Ms-Access from 32-bit Java through the JDBC-ODBC bridge
  • You could not connect to the 32-bit Odbc driver via JDBC-ODBC from 64-bit java. There was a message that you can connect only from 32-bit programs.
  • Although Microsoft provides the 64-bit Ms-Access driver, it does not work with the JDBC-ODBC driver based on 64-bit versions of Java.

Since then, there seems to be a new open source JSBC Ms-Access driver for the Ms-Access JDBC driver . I have no idea how good it is.

+2
source

You just missed something in your code right here:

 db ="JDBC:ODBC:Driver=Microsoft Access Driver (*.mdb, *.accdb); DBQ="+path; 

You need to add {} between Driver= and )=; . As below

 db ="JDBC:ODBC:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="+path; 
0
source
 final String fileName = "c:/myDataBase.mdb" Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+fileName; Connection con = DriverManager.getConnection(url,username,password); 
0
source

The problem is that you must run Java 32-bit in order to install the latest JDK and it will work

I run it using the jdk version of "jdk-7u67-windows-i586.exe"

-one
source

On a 64-bit system, you should:

  • runs as admin accessdatabaseengine_64.exe
  • run java - 7-64 bit - jre.
-one
source

if you work in NETBEANS and then unpack the ucanacess.zip file, add all jar files to the classpath using the project properties window, click on the compilation tab and add the jar file, then perform compilation and testing.

-one
source

JDBC-ODBC MS-ACCESS CONNECTION STOPPED WORKING IN JDK8. I solved the problem by installing JDK7 along with JDK8 on the same PC, after installing JDK7 I assigned it as the JDK version for use in my project as follows in Netbeans:

1.RIGHT CLICK THE PROJECT ON THE LIST> ANCHALATED PROPERTIES

2. LIBRARIES INCLUDED ON THE LEFT NAVIGATION TREE

3. COMPACT DISC BUTTON CONTROL PLATFORMS> KEYBOARD BUTTON ADD PLATFORM ...

4. NEXT MASTER, NEVER LEAVE THIS STANDARD JAVA CLICK NEXT EDITION

5.NAVIGATE TO C: \ Program Files (x86) \ Java AND SELECT JDK7 FOLDER> PRESS NEXT

6. FIELD FILLING ROOM WITH RIGHT INFORMATION ...> THEN CLICK

7. CONFIGURING JDK PLATFORM FROM LIST> CLICK CLOSE> OK

8.JDK7 SHOULD SHOW IN THE LIBRARY PACKAGE.

JDK7 in the Libraries Package Click "Back in Browser" to return here by viewing the image ...

From here everything should go smoothly.

Hope it solves your problem.

Thank you

-one
source

All Articles