• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

Connect to MS Access in Java

What are the other ways of connecting Java and MS Access except ODBC
0
sree032397
Asked:
sree032397
4 Solutions
 
girionisCommented:
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
 
riaancorneliusCommented:
0
 
enachemcCommented:
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!

 
kaliyugkaarjunCommented:
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
 
valipotorCommented:
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
 
riaancorneliusCommented:
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
 
valipotorCommented:
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
 
riaancorneliusCommented:
Sorry valipotor, I didn't see that the URLS were different, I read them as the same thing :)
0
 
valipotorCommented:
It's allright, i should have read the post before more carefully. No harm done here.
0
 
riaancorneliusCommented:
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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now