Connect MS Access in Java on Debian Linux machine - java

Currently I've developed a small desktop application as an enhancement to my project, which reads '.mdb' file and connects as an MS-Access database using 'JDBC-ODBC Driver'.
This is works fine in Windows environment, but I am unable to run the same on Debian-Linux machine.
The code is below:
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
oAccessConnection = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+mdbFileName);
}
catch (Exception oException)
{
logger.info("Exception",oException);
}
How can I diagnose the problem?

JDBC-ODBC bridge won't work in Linux machine, so you have to use other JDBC driver, which will have access to MS-ACCESS directly (not thru ODBC bridge) - try to look in this thread

Unless you can find MS Access for Linux, I don't believe this will work. MS Access needs to run on a supported operating system.
You can run MS Access on a seperate Windows box and access it remotely, or you can install Windows in a virtual machine on the same box e.g. https://www.virtualbox.org/
Or you can use a database which can be used on other OSes. (This is almost any database accept MS Access and MS Sql Server)

If you just need to manipulate the file data and don't need to run complex queries, then you could use jackcess to work with the access file (it works on any platform with no extra libraries). the only downside is that it doesn't support jdbc or have a way of executing sql queries.

Related

How can my Java program that uses Oracle Database work on other PCs?

I am new to Oracle Database and database management systems in general. At the moment I am developing a Java program that needs to use Oracle Database (contest requirement) but I am wondering, is my program only going to work on my local machine?
I used SQLite before, but that is a server-less database management system and it only connects to a file. Instead, JDBC connects to an URL like this:
Connection connection = null;
connection = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:mkyong","username","password");
So, from what I understand, if I send my program to a friend for example, in order for my program to work, Oracle Database must be already installed and configued on his PC.
With SQLite, I only needed to include a *.sqlite file with the program that the program used.
Am I missing something here? Thanks!
If your Oracle database is accessible by your friend's computer because
- it is on the same network
- there is a VPN involved
- your database is on the internet
then your friend's computer needs an Oracle JDBC driver (a small jar) but not its own installation of the Oracle DBMS.
Otherwise an installation of Oracle is required. Consider Oracle Database XE that according to the website "Oracle Database 11g Express Edition is an entry-level, small-footprint database based on the Oracle Database 11g Release 2 code base. It's free to develop, deploy, and distribute; fast to download; and simple to administer." There are Windows 64, Windows 32 and Linux 64 downloads available.

Can a Java application running on a Window's Server connect to SQL Server via Windows Authentication

Let me give some background before I ask my question. I’m at a shop that primarily runs Windows. We have several batch applications running on Windows Servers (mostly 2003). Most of these batch applications are written in C# and C++; however we have a handful of applications that are written in Java.
The batch Java applications are connecting to a SQL Server 2005 database using JDBC. Please note we are not using an application server.
Currently we store database connection information (database, username, & password) in the Windows Registry.
Unfortunately these really unfriendly auditors (bad attempt at humor) are not happy with us over the decision to store database connection information in the Windows registry.
We are now updating our batch applications to connect to SQL Server using Windows Authentatication.
Using Windows Authentatication for C# and C++ applications is not a problem; however I’m stuck on the direction to take for the Java applications.
Can anyone advise if it is possible to use Windows Authentatication to connect to a SQL Server 2005 database from a Java batch application running on a Windows server? Again we are not using an application server.
If this is possible what are your recommended approaches?
I have a strategy to simply encrypt the password which will make the auditors happy, however I would prefer to have all of my batch applications connect to SQL Server via Windows Authentatication.
You can connect to SQL Server from Java programs using windows authentication as follows:
Create a windows account for the application that would be used to run your programs. This account's credentials will be used to connect to the server.
Get Microsoft JDBC Driver for SQL Server from here.
Configure the JDBC URL as follows:
jdbc:sqlserver://<hostname>;databaseName=<DBName>;integratedSecurity=true
Configure the launcher that run the Java programs from command line to include the following JVM parameter:
-Djava.library.path="<jdbc driver dll location>"
where the location is the directory where the JDBC driver downloaded earlier is installed or extracted. It was C:\Program Files\sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\auth\x64 in my case. As Luke Woodward mentioned in the comments, the dll should be picked based on the JVM used for running these programs.
With the above configuration, the connection established to SQL Server would use the Windows Authentication Credentials of the domain user running the java program/process.
The first step is to setup ODBC, you can go to Control panel -> Administrative tools -> ODBC. Add a new DSN to connect MS SQL Server using windows authentication account following wizard setup.
The second step is the same as using SQL Server authentication account. But the only change is that the connection string is changed to: jdbc:odbc:dsn-name. There is no need to use username/password anymore, because it is already connected to the server.

Are any JDBC drivers installed as default with Windows?

I'm writing a Java program that retrieves data from an MS Access database. My code is as follows:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + databaseLocation + databaseName +";selectMethod=cursor; READONLY=true; TYPE=FASTLOAD";
con = DriverManager.getConnection(url);
I am using a basic JDBC:ODBC bridge. It seems a Type 4 driver would be better. However I'm writing the program to be used on a different PC and I would rather they do not have to install any drivers for it to work. I don't remember installing anything on my PC.
Can anyone tell me will this work with any copy of Windows? That is are the JDBC drivers I'm using installed with Windows or Java or Access by default?
No, there are no type IV JDBC drivers installed on Windows.
I'm not aware of a free type IV JDBC driver for Access.
The JDBC-ODBC bridge is available for 32-bit JVMs, but not for 64-bit. (A DLL is required that isn't part of the 64-bit JDK.)
duffymo is correct as far as I know when he / she says "there are no type IV JDBC drivers installed on Windows"
hxtt.com/access.html is not a JDBC type 4 driver it uses Samba and not a Native Protocol which is what is required for a JDBC type 4 driver.
What you need is a JDBC type 3 driver which uses its own Network protocol to communicate between the client which in your case would be the remote PC and a server component. Commercially available is the Easysoft JDBC-ODBC Bridge offers such a solution. You install the software on the machine containing the MS Access database or a machine that can use a UNC path to the access database and then you distribute the EJOB.jar file to the machines that require access to that database along with your Java application. You can use Easysoft from both 32-bit and 64-bit Java applcations.
Many powerful SQL syntax (for instance, select ... into outfile) at http://www.hxtt.com/access/sqlsyntax.html or SQL functions (for instance, GROUP_CONCAT) at http://www.hxtt.com/access/function.html are NOT supported by MS ACCESS engine at all. With HXTT Access' help, you can access local mdb/accdb file of UNIX/LINUX/MAC OS easily without any third-party component.
HXTT is AFAIK incorrect in their statement about there JDBC is type 4.
All drivers of HXTT drivers are type 4.
it uses SMB and not a Native Protocol
Wrong. It can run for embeded mode, client/server mode, in-memory mode, mapped driver, SMB protocol, http protocol, https protocol, and mobile OS.
If you choose to download and evaluate it, you will find the following information at http://www.hxtt.com/access.html ISN'T a lie:
HXTT Access contains the only type 4 JDBC(1.2, 2.0, 3.0, 4.0, 4.1) driver packages for Microsoft Access version from 95, 97, 2000, XP, 2002, 2003, 2007, to 2010, which supports transaction, embedded access, remote access, client/server mode, memory-only database, compressed database(.ZIP, .JAR, .GZ, .TAR, .BZ2, .TGZ, .TAR.GZ, .TAR.BZ2), SMB database(smb), url database(http, https, ftp), and java.io.InputStream database. Through the embedded Pure Java database engine, MS Access database can be deployed and acessed on any platform with JVM. With JDBC1.2, JDBC2.0, JDBC3.0, JDBC4.0, JDBC4.1, and SQL92 support, programmers needn't special coding, and DBA can use any Java database tool to access easily local data or remote data.

Can we connect to SQL Server 2005 database from code with out having the installation of client and server

I need to retrieve data from the database. I have the database name, username, password, servername, but I don't have the software installed in my machine. Can I connect to the db and retrieve the data from the db from database from Java code?
you need to have database drivers atleast like ODBC or JDBC drivers on your system where application runs to access the DB from other machine.
Yes. The jdbc driver .jar can be used stand alone. It logs a warning about a missing .dll, but that can be ignored unless you need to use windows auth.
From Java, it's easy as long as there is some kind of driver installed (for example, ODBC.) Try Googling connecting to db using odbc.

Type 4 JDBC driver for MS ACCESS(.mdb) database?

My Java application uses a .mdb database and i want to run this application on MAC OS for that am definitely gonna nead a TYPE 4 JDBC driver i have google and came across two
- HXTT & StelsMDB but both are out of my reach
So if any body has some alternative or suggestions please reply.
Thanks in advance
I've used jackcess to read the tables from an MDB and convert the database to sqlite3. Not ideal if you need to keep the .mdb format, but it allowed me to keep the database in a single file and made the database cross-platform.
MS Access databases on MS Windows are driven by the Microsoft Jet Engine. Different from client server database management systems like MS SQL Server or MySQL the connection to a MS Access database runs in embedded mode via OLE and some DLLs.
As far as I know there is no Jet Engine implementation for operating systems other than MS Windows. So if you want to connect to a MDB file on Mac OS a simple JDBC driver is not enough. There has to be some kind of emulation layer to emulate the Jet Engine DLLs. According to the HXTT website this is exactly the way the HXTT JDBC driver works.
From the HXTT website:
It contains a fast database engine
written in Java, which supports
embedded and server modes.
If the usage of the MS Access database format is an absolute requirement, then these kind of emulation might be the best way for you. But you have to testify if the compatibility level is high enough. (Maybe there is no way to access VBA macros contained in the MDB file.)
It seems there is no open source project doing the same kind of emulation like HXTT.
There are several alternatives. If you want an embedded database system then you can use for example
SQLite (this JDBC driver supports Mac Os) (one database file, requires some native libraries),
H2 (only a few database files, pure Java) or
Apache Derby (many database files, pure Java).
Or you can use a client server database management system, install the server on a host and connect to that host from your Mac OS machine. For that you can use for example
PostgreSQL
Firebird
MySQL
Even the pure Java databases H2 and Derby have client server modes.
I suppose UCanAccess is what you are looking for.
It is an open source Java JDBC Driver implementation which allows Java developers and jdbc client programs (e.g., DBeaver, NetBeans, SQLeo, Open Office Base, Libre Office Base, Squirrell) to read/write Microsoft Access database. Because it is a pure java implementation it run in both Windows and non-Windows Operative Systems (e.g., linux/unix). No ODBC needed.
StelsMDB is not as expensive as HXTT, still not open source...
http://www.csv-jdbc.com/stels_mdb_jdbc.htm
Have'n tried it, but evaluation copy is available.
Anyone else got suggestions? I'm looking for an opensource variant myself. Shouldn't be impossible to build on top of jaccess ...
We use stelsMDB JDBC driver at our server to read/write MDB files. It is platform-independent, so you can use it in MacOS as well.

Categories