Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cornfused about accessing a table in an Access database

 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm an old COBOL programmer learning JAVA so some of my mainframe concepts are interfering with learning new JAVA concepts.
I am going thru the book "JAVA for the COBOL Programmer" by E. Read Doke and Bill C. Hardgrave. I am also using JAVA ALL IN ONE FOR DUMMIES by Doug Lowe.

I am stuck on the meaning of the URL for accessing a table or maybe it is the DATABASE that that is used for.
So I see this:
String = url = "jdbc:pdbc:Try2";
and later that variable url is used in
DriverManager.getConnection(url,"JavaDemo","JavaIsFun");


I have in this path D:\A_Docs_none_GD\A-DATA
the following which I think is an Access Data Base: SampleDatabase_Access2007FD_Employees.mdb
And from one of the existing tables I made another table that I named "CustomerTB"

When I opened up ODBC Data Source Administrator
and went into tab System DSN
choose 'Microsoft Access Driver'
and then in next window 'OBDB Microsoft Access Setup' did an Add
I created a 'Data Source Name' by the name of 'Try2'
I click Select
and chose SampleDatabase_Access2007FD_Employees.mdb

So here is where I am stumped. I want to query the table I made CustomerTB
I am not sure what the value in the variable url should be.
Maybe is should be

String = url = "jdbc:pdbc:D:\A_Docs_none_GD\A-DATATry2";

My SQL statement is
String sqlQuery = "SELECT Name, SSNo, Address, Phone, FROM CustomerTB";



 
Aditya Karnad
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Hittle wrote:
I have in this path D:\A_Docs_none_GD\A-DATA


I'm not sure if this is the only thing wrong, but your String reference here should hold


The \\ is an escape sequence.
Click here to read more on Escape Sequences
 
Campbell Ritchie
Sheriff
Posts: 51413
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you look here you find you would probably be better using / instead of \ throughout.
 
Dave Tolls
Ranch Hand
Posts: 2103
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL should be:

The 'jdbcdbc' part tells the DriverManager which Driver to look for.
The 'Try2' tells the Driver which database you want to access.
Your ODBC maps Try2 to your .mdb file.

The other option, which doesn't involve an actual ODBC data source having to be set up, is:

where 'dbPath' is the location of your .mdb file, so 'D:/A_Docs_none_GD/A-DATA' in your case.

Since you've already set up your ODBC source you may as well use the first, shorter, one.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well just weird. I don't know why typed '\' when I meant '/'.
And I finally got it through my head that the characters after jdbcdbc: is what I might call the alias name I made up when I went into the app "ODBC Microsoft Access Setup"

So now I have
String url = "jdbcdbc:Try2";

and later on as mentioned before I have
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

but when I run the code or class I am getting this exception:

Exception caught java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

Any ideas of what might be wrong now?



 
Robert D. Smith
Ranch Hand
Posts: 214
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like asking the obvious -- have you installed the jdbc driver(s) for Access? And at one time, there used to be a 32-bit and a 64-bit driver. Not sure if that is still the case. I'm a bit out of touch at the moment, so I'm not even sure my answer is applicable.

regards,
robert
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clueless about if I did any install of jdbc drivers for Access. so, I guess not. I am on Windows7 64bit Professional. And I am using MS OFFICE 2013.
Will I need to find some 64 bit drivers for Access?

I am not sure which version of Java I am using. I did the install just months ago.
 
Dave Tolls
Ranch Hand
Posts: 2103
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Java have you got?

The JDBC-ODBC bridge was removed from Java 8, which would explain why it can't find the class.
 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Dave Tolls, that must be it. I have JAVA version 8 update 45.

So what do I do now?
 
Dave Tolls
Ranch Hand
Posts: 2103
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there's a couple of Access drivers available nowadays.
There's one called UCanAccess (but Sourceforge is down at the moment).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic