[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Connect to MS Access in Java

Posted on 2006-07-17
12
Medium Priority
?
427 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

656 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