?
Solved

Connect to MS Access in Java

Posted on 2006-07-17
12
Medium Priority
?
426 Views
Last Modified: 2012-06-22
What are the other ways of connecting Java and MS Access except ODBC
0
Comment
Question by:sree032397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 17120714
You can connect by using a type 4 driver also, like you would do to any other database. The only thing you have to do is to find such a driver. Have a look here: http://developers.sun.com/product/jdbc/drivers
0
 
LVL 9

Assisted Solution

by:riaancornelius
riaancornelius earned 500 total points
ID: 17120719
0
 
LVL 12

Expert Comment

by:enachemc
ID: 17121414
Use Hibernate (or other persistence framework). You can also use Entity EJBs.
0
Independent Software Vendors: 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!

 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 500 total points
ID: 17121679
How to communicate with a MS Access database from a Java program.

First Register the database with the Windows Naming Service

1.    Click Start|Settings|Control Panel You will see an icon which sets up an ODBC data source within the control panel. This is a simple naming system which allows your Java programs to communicate with a Microsoft database. The name of the icon will be different on each Windows version, for example it will be marked ODBC Data Sources on NT4 and be found in a folder named Administrative tools and called Data Sources (ODBC) in Windows 2000.
2.    Double click this icon.
3.    Click the add button on the window that appears.
4.    On the next window double click the line starting Microsoft Access Driver.... A new window should then appear.
5.    In the field marked Data Source Name enter a ‘nickname’ for your database i.e."dbNickName", then click the Select button.
6. Navigate to the file containing the actual database; you will know that you have reached it when the name of the file (yourDatabase.mdb) appears in the leftmost text area.
7. Select the file by clicking it and then click OK.
8. Get rid off all the windows that you have opened by clicking OK on all of them.
The database file can now be referred to as “dbNickName” within your Java programs.

How to establish a connection to the database  (import java.sql.*;)

1. Load a compatible driver. (Inside a Try – Catch block)
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

2. Create a connection object. (Try – Catch ) Supplying a protocol & DB name, userName, and password.

Connection connect;
connect = DriverManager.getConnection(“jdbc:odbc: dbNickName”, “userName”, “password”);

3. Create your SQL statement

String sqlString = “select * from aTable”;

4.    Create a Statement object and associate it with the Connection object.

Statement stat = connect.createStatement();

5. Execute the SQL statement and store the result in a ResultSet object.

ResultSet res = stat.executeQuery(sqlString);

6.    Extract the data record(s) from the ResultSet object using code inside a while(res.next()) loop.  If your table contains three columns each holding a String, String and Integer respectively then the data can be retrieved by using res.getString(1), res.getString(2) and res.getInt(3).  Where the arguments represent the position of each column in the database table (the actual table names can also be used if preferred).
        You will probably want to store the retreived data as objects in a vector and create an Enumeration object from this vector in order to manipulate the data.

7.    Close the Statement, Connection and ResultSet objects
    stat.close();
    connect.close();
    res.close();


More links

http://www.dbmdata.com/dev/connectToAccess.html

http://forum.java.sun.com/thread.jspa?threadID=200603&messageID=669121

0
 
LVL 6

Assisted Solution

by:valipotor
valipotor earned 500 total points
ID: 17122725
For a comprehensive list of MS ACCESS drivers check the  Sun's JDBC driver database:
http://industry.java.sun.com/products/jdbc/drivers .

Select MS ACCESS in the Supported DBMS(s) and click search.
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17127863
kaliyugkaarjun, look at the question:
>> What are the other ways of connecting Java and MS Access **except ODBC**

valipotor:
girionis gave that link in his first post...
0
 
LVL 6

Expert Comment

by:valipotor
ID: 17127923
riaancornelius:

Yes, I can see that the URL's are different but the page is the same. Honest mistake.

sree:

Here is another link, hopefully no one posted before :

http://jackcess.sourceforge.net/faq.html

Jackcess ia a pure Java library for reading from and writing to MS Access databases. It is not an application. There is no GUI. It's a library, intended for other developers to use to build Java applications.

Also, you can check thins library too:

http://mdbtools.sourceforge.net/

The MDB Tools project is a effort to document the MDB file format used in Microsoft's Access database package, and to provide a set of tools and applications to make that data available on other platforms.

But if the reason for not using ODBC is that you are interested in using an MS Access database in linux, you must know that ODBC drivers for linux are available too.
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17127949
Sorry valipotor, I didn't see that the URLS were different, I read them as the same thing :)
0
 
LVL 6

Expert Comment

by:valipotor
ID: 17127958
It's allright, i should have read the post before more carefully. No harm done here.
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17362569
kaliyugkaarjun doesn't really answer the question asked, but I guess it is a good answer, so unless sree wants to gives us some more info, I'm happy with your suggestion Girionis:)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question