[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1602
  • Last Modified:

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

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
somits
Asked:
somits
  • 4
  • 3
1 Solution
 
for_yanCommented:
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
 
for_yanCommented:
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
 
somitsAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
for_yanCommented:
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
 
for_yanCommented:
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
 
somitsAuthor Commented:
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
 
somitsAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now