Solved

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Posted on 2012-03-28
7
1,452 Views
Last Modified: 2013-11-24
Hi:

We're writing a java program to connect to an Access database.
This is the first time we do this (connect to an access database with java).

Here is the code:
//------------------------


            try {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (Exception e) {
                  System.out.println("JDBC-ODBC driver failed to load.");
                return;
            }

            try {
                  Connection con = DriverManager.getConnection("jdbc:odbc:ACCESSDB_8", "", "");
                con.close();
                System.out.println("Database Access connection is successfully connected.");
            } catch (Exception e) {
                System.out.println(e);
            }

//----------------

When we run this code, an exception is raised:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

It seems that we have to specify some Data source name. However, we don't know how to do it.

If you've any idea about this error, please help.
Any help is appreciated.

Thanks a lot,

Somits
0
Comment
Question by:somits
  • 4
  • 3
7 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37779437
Yes, you need to set up it through ODBC - see my response to your previous question. I doen' recommend to odo it this way - see my responsesd to previous question.
Let me know if you still want it - we can go through setting up datasource in more detail
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37779451
so if you want ODBC , go to Contrl Panel -- Admin Tools -- Data Sources -- System DSN (Tab) -- Add(button) -select  MicorosodftASccessDriver(*.mdb) - fil in DataSOurceName ACCESSDB_8) and description - does not matter what there)- Select (button) - navigate to your *.mdb

But I think on neweerr machines it is more difficcult than using the DBQ=
0
 

Author Comment

by:somits
ID: 37780196
Hi for_yan:

First, thanks a lot for all your comments.

I tried your recommendation: using
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" +  "C:\\MDBFileName.mdb";

but when I run the code, still the same error:

Here is my new code:

//--------------
try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            jdbcOdbcDriverStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="
                                        + "F:\\JAVA\\APP_DATA\\ACCESSDB_8.accdb";
           
            Connection con = DriverManager.getConnection(jdbcOdbcDriverStr, "", "");
           
            con.close();
           
        } catch (Exception e) {
            System.out.println(e);
            return;
        }
//------------------------------------

Clearly, the error
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

occurred at this line of code:
Connection con = DriverManager.getConnection(jdbcOdbcDriverStr, "", "");

Maybe, I still miss something?

Thanks a lot for all your help,

Somits
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 47

Expert Comment

by:for_yan
ID: 37780209
Try to go through ODBC - if you see there Microsoft Access Driver (*.mdb) in the choice of dropdown - then try tghis way with configuring data source. If you dont see it, then you'll need to download and install the driver from microsoft link whichn I posted in one of these questions
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37780328
Many years ago when I first connected my java program with MS Access database,
I went through Control Pnale - ODBC - and set up DataSource and then refrred to that
DataSource name in the connection string this way

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con1 = DriverManager.getConnection("jdbc:odbc:.DataSourceName","","");

at that time on all computers I wanted to do it - I had no problems with configuring DataSource name because everywhere after I clcked "Add" I saw a choice of drivers and among this choice I was finding Microsoft Access Driver (*.mdb)
I guess at that time Microsoft was installing these drivers either with the system itself or myabe with the MS Office. So I was happy and had no problems with that.

Howevere, perhaps couple of years ago I started  encountering cases on the newer machines (with Windows 7 , Vista and maybe even late XPs) , that when I was clicking "Add" I was not seeing  
Microsoft Acceess Driver in the choice.
I understand that on these newer machines MS Access diver is niot installed by default
Then I found that on such machines you need to install the driver from this microsoft page

http://www.microsoft.com/download/en/details.aspx?id=13255

with this new driver, I found that you do not need to  set up the data source but can use more direct way with this DBQ= format.

So in your case I suggest that you first go to ODBC and ccek if you are able to crete new DataSource and if Micosoft Access Driver is accessible in the dropdown menu.
Then you can use that simple connection string which just refes to DataSource name

If you cannot configure Datasource for the lack of driver in the dropdwon, then go to that microsoft page, choose the file you need to download (there are two variants - for 32 bit and for 64 bit), install it and then use the connection string of the new type (with DBQ=-)
0
 

Author Comment

by:somits
ID: 37783069
Hi for_yan:

I checked Admin Tools --> ODBC Data Source and found the following tabs:

1) User DSN
2) System DSN
3) File DSN
4) Drivers
...

I looked into User DSN and found: MS Access Database
I looked into System DSN and it's empty
I looked into File DSN and a lot of folders but nothing named MS Access Database

I select "MS ACcess Database" in User DSN and click Add.
A window named "Create New Data Source" pops up and ask "Select a driver for which you want to set up a data source". They list

a) SQL Native CLient
b) SQL Server
c) SQL Server Native Client 10.0

I don't know which one to choose but I selected c): SQL Seerver Native Client 10.0 because its drive is the latest. Then click Finish.
Another wizard "Create a Data Source to SQL Server" pops up. It asks to enter:

a) Name: (I guess the name of the data source)
b) Description: ...
c) Which Sql Server do you want to connect to

For b), I can guess. However, for a) and c) I don't know how enter them.

For a) How to give a name to a data source? Can we it any name we want?

For c) How we can specify that we need a data source to an Access database, not a SQL server?

Thanks a lot for all your help.

Somits
0
 

Author Comment

by:somits
ID: 37784093
Hi for_yan:

IT WORKS .............................

THANKS SO MUCH FOR YOUR KINDNESS TO HELP ME ON THIS.

REALLY APPRECIATED.

You're right. It must be matched the version x64 OR 32 bits for JRE & the driver.

Somits
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 79
wordcount challenge 11 78
Java / Linux and Regular Expressions 11 48
Java Jpanels and Jframe 8 20
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now