Menu

NonWritableChannelException on writePage

Anonymous
2011-11-21
2016-07-07
  • Anonymous

    Anonymous - 2011-11-21

    Hi all,

    unfortunately we encountered another excpetion. Using Version 1.2.3 still.
    Same setup as on the other exceptions. (Linux server running Tomcat, writing
    to MDF file mounted from Windows server). We didn't expect so many problems on
    using this library, but maybe we are doing something wrong initially!? We
    appreciate any help.

    This exception also interrupted our export writing to the Access file.

    Thank you all,
    cu

    Tom


    |06:47:32,240|ERROR(http-8080-7)at.package.ExportController|java.nio.channels.
    NonWritableChannelException
    java.nio.channels.NonWritableChannelException
    at sun.nio.ch.FileChannelImpl.write(Unknown Source)
    at
    com.healthmarketscience.jackcess.PageChannel.writePage(PageChannel.java:216)
    at
    com.healthmarketscience.jackcess.PageChannel.writePage(PageChannel.java:184)
    at com.healthmarketscience.jackcess.Table.writeDataPage(Table.java:1149)
    at com.healthmarketscience.jackcess.Table.addRows(Table.java:1309)
    at com.healthmarketscience.jackcess.Table.addRow(Table.java:1227)
    at at.ourpackage.WagnerExportServiceImpl.exportExportRecordsToErpSystem(Wagner
    ExportServiceImpl.java:556)
    at at.ourpackage.WagnerExportServiceImpl.doExportUntil(WagnerExportServiceImpl
    .java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(Aop
    Utils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoin
    t(ReflectiveMethodInvocation.java:183)

     
  • James Ahlborn

    James Ahlborn - 2011-11-21

    this exception looks like you are trying to write to a read-only file.

     
  • GilesM

    GilesM - 2012-04-06

    I'm seeing the same problem when I try to execute Cursor.UpdateCurrentRow. My
    database was password-protected, but I have tried it with and without the
    password on the file (I removed the password), and I know for sure that the
    file is not read-only.

    This is the code I am executing:

    public void editField(Table table, String ID, Column column, Object newData)
    {
    if (table.getColumns().contains(column))
    {
    logger.debug("Writing new data for table " + table.getName()
    + " column " + column.getName() + " and ID " + ID);
    Cursor cur = Cursor.createCursor(table);
    try {
    cur.reset();
    logger.debug("Looking for row!");
    do
    {
    Map<String, Object=""> row2 = cur.getNextRow();
    Iterator rowData = row2.entrySet().iterator();
    while (rowData.hasNext())
    {
    final Entry thisRow = (Entry) rowData.next();
    final String key = thisRow.getKey().toString();
    if ((key.matches("(?i).PropCode."))
    && (thisRow.getValue().toString().matches(ID)))
    {
    try {
    logger.debug("Found row, now putting new data");
    cur.setCurrentRowValue(column, newData);
    logger.debug("Successfully updated cursor");
    } catch (Exception e) {
    logger.debug("Nope!..>");
    e.printStackTrace();
    }
    }
    }
    }
    while (!cur.isAfterLast());
    }

    And the error I am seeing is:

    java.nio.channels.NonWritableChannelException
    at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:641)
    at com.healthmarketscience.jackcess.PageChannel.writeNewPage(PageChannel.java:
    259)
    at com.healthmarketscience.jackcess.PageChannel.allocateNewPage(PageChannel.ja
    va:273)
    at com.healthmarketscience.jackcess.TempPageHolder.setNewPage(TempPageHolder.j
    ava:115)
    at com.healthmarketscience.jackcess.Column.getLongValuePage(Column.java:1392)
    at com.healthmarketscience.jackcess.Column.writeLongValue(Column.java:1271)
    at com.healthmarketscience.jackcess.Column.write(Column.java:1478)
    at com.healthmarketscience.jackcess.Column.write(Column.java:1407)
    at com.healthmarketscience.jackcess.Table.createRow(Table.java:1828)
    at com.healthmarketscience.jackcess.Table.updateRow(Table.java:1535)
    at com.healthmarketscience.jackcess.Cursor.setCurrentRowValue(Cursor.java:931)
    at com.lughnasadh.liverfluke.FlukeFile.editField(FlukeFile.java:138)
    at com.lughnasadh.liverfluke.MainUIFrame.writeItBack(MainUIFrame.java:404)
    at com.lughnasadh.liverfluke.MainUIFrame$6.mousePressed(MainUIFrame.java:185)
    at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
    at java.awt.Component.processMouseEvent(Component.java:6035)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3983)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.jav
    a:273)
    at
    java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.jav
    a:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    All input gratefully received!

     
  • James Ahlborn

    James Ahlborn - 2012-04-06

    what is the result of File.canWrite() on the database File you are passing to
    Database.open()?

     
  • GilesM

    GilesM - 2012-04-06

    Hi,

    Just tested that - File.canWrite() returns true.

    Thanks,
    Giles.

     
  • GilesM

    GilesM - 2012-04-07

    I've done a bit more research on this one, and tired a different approach
    (using Cursor.updateCurrentRow, rather than the Cursor.setCurrentRowValue as
    before). It still doesn't work, but I get a different error this time. I don't
    know if it is significant, but the column that I an trying to update is an OLE
    type, and I am putting a big lump of binary code in there. The file was
    generated by another system that I don't have access to.

    For my investigations, I am simply reading out the current row into a Map
    object, updating the value in question (with the same data I read out of it in
    the first place for the purposes of testing) then using
    Cursor.updateCurrentRow to put it back.

    Here's my code:

    public void editField(Table table, String ID, Column column, Object newData)
    {
    if (table.getColumns().contains(column))
    {
    Cursor cur = Cursor.createCursor(table);
    try {
    cur.reset();
    do
    {
    Map<String, Object=""> row2 = cur.getNextRow();
    Iterator rowData = row2.entrySet().iterator();
    while (rowData.hasNext())
    {
    final Entry thisRow = (Entry) rowData.next();
    final String key = thisRow.getKey().toString();
    if ((key.matches("(?i).Cable ID."))
    && (thisRow.getValue().toString().matches(ID)))
    {
    try {
    row2.put(column.getName(), newData);
    cur.updateCurrentRow(row2);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    }
    while (!cur.isAfterLast());

    I'm getting this error:

    java.io.IOException: Text is wrong length for TEXT column, max 255, min 0, got
    1295
    at com.healthmarketscience.jackcess.Column.encodeTextValue(Column.java:1665)
    at com.healthmarketscience.jackcess.Column.write(Column.java:1443)
    at com.healthmarketscience.jackcess.Column.write(Column.java:1407)
    at com.healthmarketscience.jackcess.Table.createRow(Table.java:1828)
    at com.healthmarketscience.jackcess.Table.updateRow(Table.java:1535)
    at com.healthmarketscience.jackcess.Cursor.updateCurrentRow(Cursor.java:536)
    at com.lughnasadh.liverfluke.FlukeFile.editField(FlukeFile.java:143)
    at com.lughnasadh.liverfluke.MainUIFrame.writeItBack(MainUIFrame.java:404)

    I'm not sure where it's getting the TEXT from - as I said, the field I'm
    updating is an OLE field.

    Confused of South Wales..

    Giles.

     
  • GilesM

    GilesM - 2012-04-07

    One final bit of evidence for the time being.
    I have just tried this again where all I am doing now is using exactly the
    same Map<String, Object=""> returned by Cursor.getNextRow and putting it back via
    Cursor.updateCurrentRow (i.e. I have not updated any values in the original
    Map object).
    This still returns the same java.io.IOException error. Is it possible that
    jackcess does not work with OLE column types?

    Cheers,
    Giles.

     
  • James Ahlborn

    James Ahlborn - 2012-04-09

    Jackcess works just fine with OLE columns.

    the only way you can get the NonWritableChannelException is if the file is
    opened read-only. there's nothing about the type of data that you are
    manipulating that would have any affect on that.

    when you update the current row, all values in the map will be written back to
    the database, regardless of whether or not you have "modified" them. it seems
    one of the strings you are reading violates the length constraints defined in
    the mdb file.

    can you provide the actual database and some example code which exhibits the
    problem you are seeing? or at least a text dump of the table you are
    manipulating (you can call Table.toString() to get a detailed listing of the
    table as Jackcess has interpreted it).

     
  • Gord Thompson

    Gord Thompson - 2016-07-07

    One possible cause of NonWritableChannelException is when the database file is stored in the root folder of C: on a Windows machine (where mere mortals do not have write access), e.g.,

    C:/Data.accdb

     

Log in to post a comment.