| Author |
Example, MS Access Java Application
|
Todd Jaspers
Greenhorn
Joined: Aug 29, 2005
Posts: 23
|
|
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
Joined: Jul 31, 2003
Posts: 263
|
|
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 ]
|
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
|
 |
Todd Jaspers
Greenhorn
Joined: Aug 29, 2005
Posts: 23
|
|
|
Thank you Tom, I really appreciate it!!!
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
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
Joined: Aug 29, 2005
Posts: 23
|
|
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
Joined: Jul 31, 2003
Posts: 263
|
|
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
Joined: Dec 06, 2001
Posts: 3061
|
|
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
|
Java API Documentation
The Java Tutorial
|
 |
Todd Jaspers
Greenhorn
Joined: Aug 29, 2005
Posts: 23
|
|
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
Joined: Apr 15, 2013
Posts: 3
|
|
|
Thank You
|
 |
 |
|
|
subject: Example, MS Access Java Application
|
|
|