• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access database

 
Archana Pawar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The access database connection code throws an exception like :
"Datasource name not found and no driver specified"
My database file is MyDB.accdb.My connection code snippet is:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbcdbcriver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ=MyDB.accdb;";
Connection conn = DriverManager.getConnection(database, "", "");
The code is unable to connect to database.
Any solution would be appreciated.
Thanks!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You're not using Java 8, by any chance? I recall that the JDBC/ODBC bridge driver was removed from Java 8.
 
Archana Pawar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!!
 
Archana Pawar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to connect to the database MyDB.accdb.
The code is as follows:
Class.forName("Microsoft Access Driver (*.mdb,*.accdb) ");
Connection conn = DriverManager.getConnection(jdbc::MyDB.accdb, "", "");
I hope the code is right!
Any suggestions welcome!!!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already made a suggestion ; I take it you made sure that that was not the issue?
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to catch the exception, if it is not java 8 issue, and if you get any exception what is it?
 
Archana Pawar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not get any exception, however the connection doesn't seem
like is established. I hope the connection statement is correct
Connection conn = DriverManager.getConnection(jdbc::MyDB.accdb, "", "");
The system hangs and the control does not return from the database.The code
beyond this line of code is not executed.
Any suggestions welcome!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are you, or are you not, using a Java 8 JRE to run this code?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection conn = DriverManager.getConnection(jdbc::MyDB.accdb, "", "")

This can't have been what you used - it wouldn't even compile. Even if you enclosed the first parameter in double quotes, that looks nothing at all like a correct URL (or anything like your previous attempts). Where did you get the idea that that should work?

But since you haven't answered my previous question (which I asked 3 times by now, and shall not ask again), this may not matter.
 
Archana Pawar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code that I have used is enclosed in "" , not an issue!
Connection conn = DriverManager.getConnection("jdbc::MyDB.accdb", "", "");
I am using java 7. If I compile with the jdbc-odbc bridge I get error.
So I have removed the bridge code. Now I do not get error but the system
hangs. The database connection is not established.
Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case my other comment applies:

Ulf Dittmer wrote:that looks nothing at all like a correct URL (or anything like your previous attempts). Where did you get the idea that that should work?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Archana Pawar wrote:So I have removed the bridge code. Now I do not get error but the system hangs. The database connection is not established.

If you're trying to connect to a MS Access database, you have either to use the JDBC-ODBC bridge, or a native MS Access driver. As far as I know a native driver is not available for free, it can be only bought from other parties (even Microsoft doesn't provide one).

I'd suggest to step back a bit and consider using another database. There are a plenty of free databases that can be used easily with Java. MS Access is a pain to work with, especially from Java - with the ODBC bridge you'll be constantly running into issues. (I don't have any experience with the native - but paid - MS Access drivers).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic