• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Example, MS Access Java Application

 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I've been programming for quite some time in other languages, but I'm still real green when it comes to Java. Can anyone provide me with an example Java Application or Applet that shows very simply, how I would create, connect, and query an MS Access database using ODBC?

I've got millions of books, but I'm the kind of person who learns best by actually working on something, rather than sitting down in a chair and reading a reference manual. I just don't have the attention span for it.

Any help would greatly be appreciated.



Thank you!

Todd
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Todd,

Here's a simple one a did a while ago. You might get more response if you posted this in the JDBC forum. Using this method, you need a ODBC data source (in this case named POData). You can also do what is know as a DSNless connection by using the follow URL as the ODBC_SOURCE:





Cheers,

[ September 22, 2005: Message edited by: Tom Blough to add DSNless info]
[ September 22, 2005: Message edited by: Tom Blough ]
 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tom, I really appreciate it!!!
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Todd,

One thing I should point out is all the "magic numbers" in columnNames.getString() methods. Those are documented in the Java API for DatabaseMetaData.getColumns().

Have fun,
 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom Blough:
Todd,

One thing I should point out is all the "magic numbers" in columnNames.getString() methods. Those are documented in the Java API for DatabaseMetaData.getColumns().

Have fun,


Hey Tom, one quick question,

it does error out when it attempts to connect to the database...


for the ODBC / PATH string, I have:



I also include java.sql.*;

Is there anything that I am missing that I should have done?

The error I get is:

"Error connecting to PO Database
java.lang.ClassNotFoundException: sun.jdbc.odbc.jdbcodbcdriver"


Thanks!!

Todd
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Todd,

Did you set up idxAnalyzerCustom as a user or system data source? If you use that form you need to configure an ODBC datasouce on your machine with that name. For MS Access you can use the alternative URL for the getConnection method that specifies the file/path to the .mdb file that I wrote about.

Java is also case sensitive. sun.jdbc.odbc.JdbcOdbcDriver is not the same as sun.jdbc.odbc.jdbcodbcdriver. The former is correct.

Tom
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Tom points out, you have the wrong class name for the driver. Notice that since your code has the class name hiding in a String, the compiler cannot catch any errors if you use the wrong name. Instead, the JVM will complain because the class is incorrect.

HTH

Layne
 
Todd Jaspers
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom Blough:
Todd,

Did you set up idxAnalyzerCustom as a user or system data source? If you use that form you need to configure an ODBC datasouce on your machine with that name. For MS Access you can use the alternative URL for the getConnection method that specifies the file/path to the .mdb file that I wrote about.

Java is also case sensitive. sun.jdbc.odbc.JdbcOdbcDriver is not the same as sun.jdbc.odbc.jdbcodbcdriver. The former is correct.

Tom


Damn! That must be it then...

I did: "sun.jdbc.odbc.jdbcodbcdriver"

Yeah, I already have an ODBC set up with that exact name. "idxCustomAnalyzer".


Thanks everyone for all the help, I really appreciate it.

I'm used to Delphi and Visual Basic, neither of which care very much for the case of the variables and whatnot.

This is very similar to Mumps with respect to case sensitivity.


Thanks!!!
 
Dardan Bala
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic