Jdbc Connection in Java Example With Ms Access
MS Access JDBC Driver -- Connecting MS Access with Java
To connect Java with MS Access, you need a JDBC driver. Although Microsoft do not produce a JDBC driver for MS Access, Easysoft provide two Microsoft Access JDBC drivers. Use these JDBC drivers to provide the connectivity layer between your Java code and MS Access database.
- Download Type 2 MS Access JDBC driver for Windows
The Easysoft JDBC-Access Driver connects Java running on Windows to local MS Access databases. For more information, see the JDBC-Access Driver Getting Started Guide.
- Download Type 3 MS Access JDBC driver for Linux and Unix
The JDBC-ODBC Bridge connects Java running on Linux or Unix to remote MS Access databases. For more information, see this tutorial.
Accessing MS Access from Java
This tutorial shows how to access MS Access databases from Java.
Contents
- Prerequisites
- Assumptions
- Configuring the Microsoft Access ODBC Data Source
- Running the Demo Applet
- Running the Demo Application
- Common Problems
Prerequisites
- An installed and licensed Easysoft JDBC-ODBC Bridge (JOB) server on a supported Windows platform that has Microsoft Office installed.
If you have not yet installed the JOB software or you are having problems with the installation, use our Getting Started Guide to help you through the installation.
- An existing Access database file (.mdb) on the Windows machine.
Assumptions
- You accepted the default options during the install.
- This tutorial was written assuming the demonstration clients were installed on the same Windows machine as the JOB server.
You can check to see if you have these installed by choosing Start > Programs > Easysoft > JDBC-ODBC Bridge.
From here you should see both an Applet demo and an Application demo.
- We have also assumed that you have installed the JOB software as a valid Windows User who has access to the target database.
Configuring the Microsoft Access ODBC Data Source
You will find the ODBC Administrator within Administrative Tools from your Control Panel.
From here you will create your new System DSN. Click the Add button and then select the Microsoft Access Driver and click Finish.
Give your DSN a meaningful name and click Select. Here you will be able to browse to your existing .mdb file.
Once you have selected the database you want to access, click OK and then OK again to exit the dialog box. You have now created your data source.
Running the Demo Applet
Within your services manager, make sure that the JOB service is running, and then open a web browser and go to the following URL http://localhost:8031.
This will open the JOB Web Administrator where you have many configuration options. On the left hand side, you will see a Test Applet link. This will show you a box with various parameters. The Logon User and Password should be the same as your valid Windows details.
Once you have entered your username and password, click the Connect button. This will then display a pop-up box:
As you can see from the image, we have created a system DSN that points to northwind.mdb called NORTHWIND. (There is a Northwind database included in most versions of Microsoft Office.) If you have more than one system DSN, your newly created DSN will appear at the bottom of the drop down list.
From here, simply select the DSN you wish to connect to and click Connect. (You will not need to add a database username and password as the Access database will use NT authentication.)
Once connected, you will see a list of tables. You can issue a simple select * from table
by double clicking the table you wish to query. Alternatively, you can issue your own SQL in the SQL field.
This will return the result set in an applet window:
Running the Demo Application
To run the Demo Application, choose Start > Programs > Easysoft > JDBC-ODBC Bridge > AWT Application Demo.
This should now display the demo application:
You can see that the connection URL already has the first part of the connection string in it -- jdbc:easysoft:
The complete connection string should take the form of:
jdbc:easysoft://servername/datasource:logonuser=username:logonpassword=password
From here, you do not need to add any further details. Simply click Connect.
From here, you will be able to see a list of tables from your Access database. The same applies to the SQL commands as it does in the Demo Applet section. Simply issue your SQL command and click Submit.
Common Problems
Why can't I connect to my Microsoft Access .mdb file using the Easysoft JDBC-ODBC Bridge?
The problem is likely to be that the Microsoft Access .mdb file is on a mapped network drive that can only be accessed by a named user.
There are three possible solutions:
- Move the .mdb file to a drive that can be accessed by a service.
- Run the JOB service as the user who has access to the drive/file.
- Add the following attributes to the JDBC connection URL:
logonuser=username:logonpassword:password
Why do I get error "[JOB] Connection failed[JOB] RPC Exception: access denied (java.net.SocketPermission ip address/server name:8031 connect,resolve)" when trying to connect in the test applet using a fully qualified JDBC URL?
If you have run the test applet from the Start menu, the browser will default to 127.0.0.1 (localhost). This will then be the only IP address/server name you will be able to use in your JDBC URL. You will not be able to use the server's actual IP address/server name unless you have used either of them in your initial browser address (http://ip address/server name:8031).
Why do I get error "RPC Exception: access denied java.net.SocketPermission" in the JOB applet?
Check that your JDBC connection URL is connecting to the same machine as your browser. For example, http://127.0.0.1:8031 is not the same as the machine name / IP address, so in your connection URL it must match:
jdbc:easysoft://servername/datasource:logonuser=username:logonpassword=password
Why do I get the error "Client denied access due to access control rule"?
The machine you are running the JOB JDBC driver on has attempted to connect to the specified server (where the JOB Server is running) but there is an access control rule on the server that denies your client access. You need to use the JOB web administration interface to examine the access control rules. Point a web browser at:
http://myserver:8031
Then select Security. The access control rules are defined on this page.
Microsoft Access ODBC Driver
Easysoft also produce an MS Access ODBC driver for Linux and Unix platforms.
- MS Access ODBC driver
Article Feedback
Source: https://www.easysoft.com/applications/microsoft-access/jdbc-odbc.html
0 Response to "Jdbc Connection in Java Example With Ms Access"
Postar um comentário