I am considering using a Microsoft access database for a Java project. My question is, if I use a Microsoft access database and I complete my project and run it as a jar file on any computer/operating system, does any computer/ operating system need to have Microsoft access installed on it, particularly if the database needs to be put on a GUI on the java program and the administrator of the program can add and remove entries.
You will have to install the access odbc driver on any machine that accesses the database. I think you can do this by installing the Access runtime stuff without installing all of Access. Keep in mind that this sort of data-access is file-level, so your performance will be very poor. I'd suggest that you use a real database (postgres, mysql, sql server, oracle) or maybe a lightweight one such as SQL Server express and then accessing that database using either an odbc-jdbc bridge or preferably a native jdbc driver. Using a native jdbc driver will let you run your app from a non-windows environment.
You can use a Access Database via the JDBC-ODBC bridge on every Microsoft Windows system without to install Microsoft Access. You only need the Access Database Engine (ACE) formerly known as Jet Database Engine. ACE is part of current Windows versions. For older ones it may be necessary to install the Microsoft Data Access Components (MDAC).
Using a Access Database from Java has some disadvantages:
This is a type 1 driver with native code. Generally pure Java JDBC drivers are more performant.
With JDK 6 the JDBC-OLE bridge was somewhat enhanced. But there are still some problems with charsets and CLOBs.
Your application is restricted to Microsoft Windows operating systems.
According to the JDK 7 JDBC-ODBC bridge guide the JDBC-ODBC bridge will be removed in JDK 8:
The JDBC-ODBC Bridge should be considered a transitional solution; it will be removed in JDK 8. In addition, Oracle does not support the JDBC-ODBC Bridge. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.
So if there is any chance to use another database for your project, you should avoid using Microsoft Access together with Java.
There are lots of alternatives with far more better JDBC drivers.
If you want a small footprint embedded database, there are:
Java DB (part of the JDK), also known as Apache Derby
H2
HSQLDB
SQLite e.g. with Xerial driver
(Java DB, H2 and HSQLDB are pure Java solutions)
If you prefer a client server solution, for most commercial and open source there exist full-fledged JDBC drivers.
Oracle
Microsoft SQL Server (the server has to run on Windows but your Java client can run on every OS that supports a JVM. See Microsoft JDBC Driver for SQL Server Support Matrix)
PostgreSQL
MySQL
Related
The question is pretty self-explanatory, but below is some more info about the situation:
I am building a Java program that will be replacing a program that consists of an Excel user interface with an Access database. The Excel program connects to the Access database and communicates with VBA. But, so far there has only ever been one user at a time. Now that the program is due to expand, we need many users to be able to write to any table at the same time.
Access allows multiple users to connect at once, of course. This is not possible in HSQLDB, which is what prompted the question. Obviously, this is better accomplished with a server, but the plan is to build the program using the current database and then accomplish the transition to a server later.
Thanks in advance
In order to support multiple concurrent users (processes) writing to an Access database you must use the Access Database Engine. The options to do that from a Java application are:
Use Java's own JDBC-ODBC Bridge and the Access ODBC driver. (Note that the JDBC-ODBC Bridge was removed from Java 8.)
Use a third-party JDBC-ODBC Bridge and the Access ODBC driver.
Use a third-party JDBC driver that works with the Access Database Engine (if such a thing exists).
Note especially that the UCanAccess JDBC driver does not use the Access Database Engine and therefore does not support multiple concurrent users (processes) writing to the Access database.
You can do it. I have a similar application that I use. In version 1.8 of Java, the ODBC bridge was removed, so you'll have to look into using a separate library to connect, assuming you are using 1.8 or above. For me, it's way slower, but it does work. check out
Removal of JDBC ODBC bridge in java 8
I use "Ucanaccess" for my program, which is one of the suggestions in that question.
i typed a single program to connect to a access database and display a single record.
but when i run the program, there seems to be an issue with the drivers.
(i'm just getting started in java)
** the DNS & table name are correct
The JDBC-ODBC bridge driver has been removed from JDK 8. Any tutorials you see that use Access probably depend on this class. It's been part of Java for 20 years, so I'm sure you'll find lots of examples that are now obsolete.
You'll either have to buy a JDBC driver for Access or use a real database like MySQL, PostgreSQL, etc.
For school project I had to make program in Java that uses data base and to do so I had to import to that project file ojdbc6.jar. I know that without it I couldn't use data bases but I don't really know what is this file. Could someone explain? How such file is called and what exactly is its purpose?
Simply stated, a JDBC driver is a suite of classes that map the functionality required by the JDBC API onto the functionality provided by a specific kind of database.
Each database uses a different "wire protocol" to communicate between code running in a database client and the database server. JDBC "abstracts that away" so that a Java program can talk to any vendor's database (more or less1). The JDBC driver is the "glue" that makes the abstraction work.
In the Oracle case, there are multiple JDBC drivers, for various purposes including
Thin drivers versus OCI or server-native drivers (OCI & server-native drivers depend on platform specific native libraries)
Client-side versus server-side drivers (server-side libraries are optimized for cases where the client code is running on the database server machine ... for example.)
Drivers for different versions of Java; e.g. supporting different JDBC conformance levels.
The "ojdbc6.jar" file constitutes the Oracle thin client-side JDBC driver which is compatible with Java 6 (JDBC level 4.0).
For more information, read the Oracle JDBC FAQ.
1 - There are a couple of issues that make cross-database compatibility difficulty. Firstly, different databases support different dialects of SQL and provide different sets of SQL data types. Secondly, certain database vendors (including Oracle, before they bought Sun) have implemented non-standard extensions to JDBC.
I've been searching for the solution to open a .accdb database and read/write date from and into this file. The file is saved locally and not on a server and the solution should work without additional libraries.
Can someone help me?
Thank you for your advice
My recommendation would be to use UCanAccess.
The other common approach on Windows is was to use the JDBC-ODBC Bridge in conjunction with the Microsoft Access ODBC driver, but
that method has some limitations, particularly with respect to full Unicode support, and
the JDBC-ODBC Bridge has been removed from Java SE 8 and is not supported (ref: here).
For more information on UCanAccess see
Manipulating an Access database from Java without ODBC
There is an Apache Licensed Java library called Jackcess that allows reading/writing MS Access files.
Will code that communicates with a Ms Access 2007 database work with a Ms Access 2003 database as well? And vice versa. How compatible is all the JDBC stuff with different versions?
Thanks.
There is an odbc-jdbc bridge, so Java can connect to everything you can setup an ODBC driver to.
Of course, the drivers mostly just "pass" the SQL to the database, so if your code used querys specific of a database they will work on that database but won't on anything else.
Although SQL is a standard, db vendors provide "extra" functionality that is not necessarily standard. Depends on your usage. I am not an expert in MS Access, but I would say assume it is not compatible until you are able to prove that it is
It would depend on your jdbc driver, but as long as you're not doing any vender specific calls, (ie: custom types for cursors or vender specific sql) you shouldn't have any problems.
So to answer your question, the jdbc code will port, but the sql may not.
Is the MS Access 2007 database in ACCDB format? If so you need to use the appropriate ACE driver. Now this will work just against an Access 2003 format database file so long as ACE is installed on the client system. If not then you'll want to use Jet 4.0 which is part of every Windows OS since Windows 2000.