2014-10-17 119 views
0

我有一個「DBF」文件我需要更新從我場一欄,我使用xBaseJ API做「DBF」的操作,我的代碼如下:xBaseJ更新已不能正常工作

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

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

更新不工作。請幫助他們

回答

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();