xBaseJ更新无法正常工作

时间:2014-10-17 04:11:04

标签: java dbf

我有一个'DBF'文件我需要更新我的字段中的列,我使用xBaseJ API来执行'DBF'操作,我的代码如下:

         DBF classDB=new DBF("ABC.dbf");

        NumField xval = (NumField) classDB.getField("X"); 
        classDB.read();
        System.out.println(" X= " + xval.get());  
        xval.update(xval++);

更新无效。请帮助人

1 个答案:

答案 0 :(得分:0)

您必须将.put()值添加到要更改的项目中。然后在DB项目上调用.update():

DBF classDB=new DBF("ABC.dbf");

NumField xval = (NumField) classDB.getField("X"); 
classDB.read();
System.out.println(" X= " + xval.get());  

// the .get() function returns a space padded string, so you need to .trim() 
// it and use Integer.parseInt() to make it an integer for the addition of 1
xval.put(Integer.parseInt(xval.get().trim()) + 1);

// Once all changes are made with one or more .put() calls use .update() 
// on the database itself
classDB.update();