Jeremy Crouch Jeremy Crouch - 1 year ago 132
SQL Question

NonWritableChannelException when trying to update an Access database

Using UCanAccess for the first time for a project and I am having a lot of trouble inserting a row into one of my database tables (in Microsoft Access).

My code makes sense but once I execute I end up getting the same error every time, even though NetBeans is able to connect to my database.

package Vegan;

import java.sql.Connection;
import java.sql.DriverManager;

public class connectionString {

static Connection connection = null;

public static Connection getConnection()
connection = DriverManager.getConnection("jdbc:ucanaccess://C://MyDatabase1.accdb");
System.out.println("---connection succesful---");

catch (Exception ex)
System.out.println("Connection Unsuccesful");

return connection;

package Vegan;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DB {

private static ResultSet rs = null;
private static PreparedStatement ps = null;
private static Connection connection = null;

public DB() {
connection = connectionString.getConnection();

public void AddTest() {
try {

String sql = "INSERT INTO CategoryTbl(CategoryName) VALUES (?)";
ps = connection.prepareStatement(sql);

ps.setString(1, "Flours");
} catch (Exception ex) {


After that, when I execute the the AddTest() method, I get this system output:

---connection succesful---
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(
UCAExc:::3.0.6 null
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(
at com.healthmarketscience.jackcess.impl.TableImpl.writeDataPage(
at com.healthmarketscience.jackcess.impl.TableImpl.addRows(
at com.healthmarketscience.jackcess.impl.TableImpl.addRow(
at net.ucanaccess.converters.UcanaccessTable.addRow(
at net.ucanaccess.commands.InsertCommand.insertRow(
at net.ucanaccess.commands.InsertCommand.persist(
at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(
at net.ucanaccess.jdbc.UcanaccessConnection.commit(
at net.ucanaccess.jdbc.AbstractExecute.executeBase(
at net.ucanaccess.jdbc.ExecuteUpdate.execute(
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(
at Vegan.DB.AddTest(
at Vegan.TestDB.main(
BUILD SUCCESSFUL (total time: 1 second)

With no changes being made to the database when I check on it again Access.
What could be causing this, and what does the error message mean? Thank you

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Gord Thompson Gord Thompson
Answer Source

"java.nio.channels.NonWritableChannelException" means that the database file cannot be updated. In your case that was because the database file was in the root folder of the Windows system drive (C:\) and mere mortals have restricted permissions on that folder.

Solution: Move the database file to a folder where you have full write access.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download