Hello fellas! In this article, I’ll explain what’s JDBC and why it’s used. Why sometimes JDBC fails to connect with MS Access (.accdb). And how UCanAccess solves this problem. Last because least important, how to successfully compile and run the program from the terminal.

What’s JDBC?

Java Database Connectivity(JDBC) is a standard API used in Java to connect and interact with databases. It allows Java programs to execute SQL queries, retrieve data, and update databases regardless of the database type _ as long as a suitable driver is available.

So, JDBC provides: –

  • Database connections
  • Query execution
  • Result processing

Typical JDBC workflow: –

  1. Load database driver
  2. Establish a connection
  3. Execute SQL queries
  4. Process results
  5. Close the connection

Why JDBC Needs a Driver?

JDBC doesn’t know how to talk to databases like MySQL, PostgreSQL, MS Access, and Oracle etc. Each database requires a driver which acts as a translator between the Java and the database engine.

Now, here comes the real problem with the accurate solution. 🙂

Why MS Access (.accdb) Is a Problem?

MS Access databases primarily exists in two formats: .mdb and .accdb. But the real issue isn’t the database file formats, but rather the Java version being used.

Earlier versions (up to Java 7) had a built-in component called JDBC-ODBC Bridge. This bridge allowed the Java applications to communicate with databases through ODBC drivers. Since, Microsoft provides ODBC drivers for MS Access, connecting Java to .mdb and .accdb wasn’t an issue. However, this JDBC-ODBC driver was outright removed for some performance and security concerns later.

That’s why Java 8 or later versions were failing to use ODBC-based connectivity, even if the database and ODBC were correctly installed.

Therefore, we need a 3rd party solution and this is UCanAccess driver.

Why UCanAccess?

UCanAccess is an open-source JDBC driver that allows Java to connect to .mdband .accdb files.

Advantages: –

  • No ODBC configuration required
  • Works with modern Java versions
  • Easy setup
  • Actively maintained

This is the reason that makes it suitable option for MS Access with Java. Make sure you download this driver and extract the file contents. At the moment, I’m writing this, I had the file named UCanAccess-5.0.1.bin downloaded.

I’ve the following hierarchy in my VS code: –

JavaAccessTemplate
├── bin
├── lib
│   ├── ucanaccess-5.0.1.jar
│   ├── commons-lang3-3.8.1.jar
│   ├── commons-logging-1.2.jar
│   ├── hsqldb-2.5.0.jar
│   └── jackcess-3.0.1.jar
├── src
│   └── com
│       └── myproject
│           └── JdbcEx.java
└── .vscode
    └── settings.json
  • bin folder will have .class bytecode files that .java file will create. It’s for managerial purposes to keep working place tidy.
  • lib folder = All the *.jar files extracted from UCanAccess-5.0.1.bin.
  • Created src folder having com and myproject sub-folders. And placed java file inside this myproject.
  • Then .vscode with the file settings.json.

you can have .java directly inside src. For sake of learning, it’s done this way. So that we can know if our hierarchy for .java says: –

`├── src
│ └── com
│ └── myproject
│ └── JdbcEx.java

Then, never forget to add package com.myproject at the top of .java program. Otherwise, VS-code won’t know where to look for .java file if you’re running command inside JavaAccessTerminal directory.

Add the following code inside .vscode/settings.json: –

{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/*/.jar"
]
}

Above steps allow: –

  • Correct source folder detection.
  • Compiled .class files go into bin.
  • External libraries load correctly.

Compiling and Running from Terminal

Normal commands for running java program from inside G:\codes\Java\JavaAccessTemplate: –

javac src/com/myproject/JdbcEx.java
java src.com.myproject.JdbcEx

But for database and above setup we made: –

javac -d bin -cp "lib/*" src/com/myproject/JdbcEx.java
java -cp "bin;lib/*" com.myproject.JdbcEx

Conclusion: –

Using MS Access with Java is absolutely possible — but it requires:

  • The correct driver (UCanAccess)
  • Proper folder structure
  • Correct classpath usage
  • Exact column naming

Categorized in:

Technology,

Last Update: December 26, 2025