javadbf开发包有谁用过啊,他支不支持按字段名称赋值写入一条记录,就像操作一个数据库表一样,现在好像只能按照顺序给他放到一个数组里,难道只有这种方式吗,这样很容易弄错啊???
还有就是当写入一条记录后,能不能得到这条记录的序号或编号什么的???

解决方案 »

  1.   

    这个方法会根据你传入的数据信息自动生成DBF文件# public static void generateDbfFromArray(   
    #   
    #                                    String dbfName,   
    #   
    #                                    String[] strutName,   
    #   
    #                                    byte[] strutType,   
    #   
    #                                    int[] strutLength,   
    #   
    #                                    Object[][] data   
    #   
    #                                   )   
    #   
    # {   
    #   
    #    OutputStream fos = null;   
    #   
    #    try  
    #   
    #    {   
    #   
    #        int fieldCount = strutName.length;   
    #   
    #        DBFField[] fields = new DBFField[fieldCount];   
    #   
    #        for(int i=0;i<fieldCount;i++)   
    #   
    #        {   
    #   
    #           fields[i] = new DBFField();   
    #   
    #           fields[i].setName(strutName[i]);   
    #   
    #           fields[i].setDataType(strutType[i]);   
    #   
    #           fields[i].setFieldLength(strutLength[i]);   
    #   
    #        }   
    #   
    #        DBFWriter writer = new DBFWriter();   
    #   
    #        writer.setFields(fields);   
    #   
    #        for(int i=0;i<fieldCount;i++)   
    #   
    #        {   
    #   
    #        writer.addRecord(data[i]);   
    #   
    #        }   
    #   
    #        fos = new FileOutputStream(dbfName);   
    #   
    #        writer.write(fos);   
    #   
    #    }   
    #   
    #    catch(Exception e)   
    #   
    #    {   
    #   
    #        e.printStackTrace();   
    #   
    #    }   
    #   
    #    finally  
    #   
    #    {   
    #   
    #        try{   
    #   
    #        fos.close();   
    #   
    #        }catch(Exception e){}   
    #   
    #    }   
    #   
    # }
    好像只能一条一条取数据,其他的你自己看下api doc吧。
      

  2.   

    xizhiyao的那段代码有问题的
    # for(int i=0;i<fieldCount;i++)   
    #   
    # {   
    #   
    # writer.addRecord(data[i]);   
    #   
    # }  i<fieldCount改成i<data.length