Issue Updating DBF File

Help
Anonymous
2012-06-07
2013-04-24

  • Anonymous
    2012-06-07

    hi,
    I'm trying to update a dBase IV DBF file, and having some problems; it appears that the header is incorrect after the update. The update code is:

                    DBF dbfConn = new DBF(dbfFilename);
                    int fieldCount = dbfConn.getFieldCount();
                    Field[] dbfFields = new Field[fieldCount];
                    for (int i = 1; i <= fieldCount; i++)
                    {
                        dbfFields[i - 1] = dbfConn.getField(i);
                    }
                    dbfConn.gotoRecord(1);
                    for (Vector tableDataRow : dataRows)
                    {
                        for (int i = 0; i < fieldCount; i++)
                        {
                            dbfFields[i].put(tableDataRow.get(i).toString());
                        }
                        dbfConn.update();
                    }
                    dbfConn.close();
    

    The header is corrupt after the update completes, it seems as if the new header is written at the end of the existing header, but I'm not certain. For my current testing purposes I'm just using String and numeric data so the Field.put(String) call works as expected. No other process has a handle to the file. I'm limited to updating the file in place rather than deleting and recreating it.

     
  • Joe McVerry
    Joe McVerry
    2012-12-29

    Need more information,  Can you supply the original and the resultant dbf files.