Java‎ > ‎

Baca DBF via Java

Berikut adalah code Java untuk membaca file DBF (XBase). 

Library yang dibutuhkan javadbf, linknya sebagai berikut :
Untuk contoh penggunaan lebih lanjut dapat dilihat di source code Kettle di repository svn Kettle.




BacaDBF.java

package com.phi.rdbms;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.linuxense.javadbf.DBFException;
import com.linuxense.javadbf.DBFField;
import com.linuxense.javadbf.DBFReader;


public class BacaDBF {
	private String      dbfFile;
	private DBFReader   reader;
	private InputStream inputstream;
	private byte        datatype[];

	public void baca()
	{
		if (inputstream==null)
			try {
				dbfFile = "C:/pentaho-id/MS_PRODU.DBF";
				inputstream = new FileInputStream( dbfFile );
				reader = new DBFReader(inputstream);
				System.out.println("All oke");

				datatype = new byte[reader.getFieldCount()];
				System.out.println("Daftar Nama Fields");
				System.out.println("==================");
				for( int i=0; i<reader.getFieldCount(); i++)
				{
					DBFField field = reader.getField(i);
					System.out.println(field.getName());
				}
				while(true)
				{
					Object rowobj[] = reader.nextRecord();
					if (rowobj == null) System.exit(0);
					for( int i=0; i<reader.getFieldCount(); i++)
					{
						System.out.println(rowobj[i]);
					}
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (DBFException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

	public static void main(String[] args) {
		new BacaDBF().baca();
	}
}

Artikel Terkait

ċ
BacaDBF.java
(2k)
Feris Thia,
Oct 7, 2009, 2:31 AM
ċ
MS_PRODU.DBF
(6k)
Feris Thia,
Oct 7, 2009, 2:31 AM
Comments