NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Netbeans Java to connect MS Access Database error

Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message

Joined: 16 Dec 2011
Posts: 2

PostPosted: Fri Dec 16, 2011 7:07 pm    Post subject: Netbeans Java to connect MS Access Database error Reply with quote


I have ms access connection database with java, I used the this code

String url = "jdbc:odbc:Driver={Microsoft Access Driver " +
"(*.mdb, *.accdb)};DBQ=C:\\Users\\SERVER\\Desktop\\Law Sistem\\Database1.accdb";
Connection con = DriverManager.getConnection(url);

and I toke this error

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(
at sun.jdbc.odbc.JdbcOdbc.standardError(
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(
at sun.jdbc.odbc.JdbcOdbcDriver.connect(
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at javaapplication4.JavaApplication4.main(
Java Result: 1

How can I fix this ? Or connect that ?
Back to top

Joined: 16 Dec 2011
Posts: 2

PostPosted: Sun Dec 18, 2011 11:02 am    Post subject: Reply with quote

Is there anyone to help me please ?
Back to top

Joined: 16 Apr 2009
Posts: 114

PostPosted: Mon Dec 19, 2011 9:32 am    Post subject: Reply with quote

The Exception Messages contains the reason: "Data source name not found". The sun.jdbc.odbc.JdbcOdbcDriver is a bridge and depends on an existing ODBC driver.

On the windows operating system the Microsoft Access Driver is only 32 Bit. So you have to start the appropriate ODBC data source Administrator odbcad32.exe, on 64 Bit Windows whithin the %WINDIR%\SysWOW64 directory and the Java JVM running your application must run in 32 Bit mode.

With the ODBC data source Administrator you have to create a data source with the "Microsoft Access Driver" and give it a name, e.g. "MyAppDataSource". After creating a data source, you can access ist with the JdbcOdbcDriver throuhg it's name via the URL "jdbc:odbc:MyAppDataSource".

You can't define an Access file and hope, that the JdbcOdbcDriver creates a connection. Because it is a bridge, it will use an existing ODBC driver - the "Microsoft Access Driver" or any other which is capable to manage Access databases and redirect JDBC calls to that ODBC driver as ODBC calls. The ODBC driver accesses data sources through their names - maybe that some can create them automatically by giving them a file name, but the Microsoft Access ODBC driver doesn't that.
Back to top

Joined: 20 Feb 2012
Posts: 1

PostPosted: Mon Feb 20, 2012 4:36 am    Post subject: Reply with quote

I know the post was years ago but I felt like answering the question for those who are just experiencing this right now. It took me a while to know the answer to the question so here's the solution:

Follow the "Running the 32-bit JVM".

All you have to do is find the netbeans.conf in the installation folder of your netbeans and change the directory from something like this:

netbeans_jdkhome="C:\Program Files\Java\jdk1.6.0_24"

to this:

netbeans_jdkhome="C:\Program Files (x86)\Java\jdk1.6.0_21"

The problem is netbeans might be running in 64 bit but MS Access only support 32-bit. So doing this would hopefully solve the problem.
Back to top

Joined: 17 Apr 2013
Posts: 1

PostPosted: Wed Apr 17, 2013 4:24 pm    Post subject: Netbeans Java to connect MS Access Database error Reply with quote

I had a similar problem after upgrading to Microsoft Office Access 2010. Suddenly, my NetBeans project would not work. I was using:

String filename = IniFileProcs.pgmProps.getProperty("ResultFile");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
database+= filename.trim() + ";DriverID=22}"; // add on to the end
con = DriverManager.getConnection( database ,"","");

I added the *.accdb as listed in several places and that didn't help. When I went to Control Panel in Windows 7, ODBC Sources, click on MS Access Database I would get the error: the setup routines for the Microsoft Access Driver ODBC driver could not be found. Please reinstall the driver.

Then I realized that the control panel was running the 64-bit ODBC Administrator. So I ran from the command line C:\Windows\SysWOW64\odbcad32.exe. This brings up the 32bit administrator and makes much more sense.

To get NetBeans to properly open a MS Access file, I found that I needed the 32bit Java SDK. In installing the latest NetBeans, it only installed the 64bit version. I downloaded the newest JRE and SDK in both 64 and 32 bit and installed all four. Then went to the control panel and uninstalled all the old versions.

In NetBeans I had put the -J-d32 in the VMOptions box on the Run tab of the Properties box. All this did before was tell me that I didn't have the 32bit VM installed. After installing the new 64 and 32 bit SDK, I went to Project Properties, Libraries, manage platforms and Added a new platform. I simply pointed to the 32 bit SDK in C:\Program Files (x86)\Java\jdk1.7.0_21. I added 32-bit to the name so I would know the difference. Then under Project Properties, Libraries, I chose the new 32bit platform I just created. I also removed the VMOptions mentioned above. Suddenly the connection to the Access DB worked fine...

As explained in other posts, Access runs in 32 bit and Java was trying to run in 64bit. This caused the connection problem. Thus, changing the project to 32 bit fixed the problem.

As a side note: after getting this to work, I hit a bug in connecting to MySQL DB which is most likely unrelated to this problem. "java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp" This was fixed by adding &zeroDateTimeBehavior\=convertToNull to my Datasource definition:

Hope this helps... Keywords: ODBC Access 2010 2007 Java Netbeans IDE 7.3 Win7 MSAccess Database
Back to top

Joined: 29 Dec 2012
Posts: 8

PostPosted: Fri May 31, 2013 5:37 pm    Post subject: MS Access database connectivity in JAVA - netbeans Reply with quote

This tutorial will help you to achieve this... Have a look... Very Happy Very Happy
Back to top

Joined: 12 Feb 2016
Posts: 1
Location: aaaaaa

PostPosted: Fri Feb 12, 2016 7:10 am    Post subject: Reply with quote

All you have to do is find the netbeans.conf in the installation folder of your netbeans and change the directory from something like this: ????

== ==
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo