生成foxpro数据库文件

本文介绍了一种从Oracle数据库导出数据至FoxPro的方法,使用了xBaseJ开源项目来生成*.dbf文件,通过具体示例展示了如何创建字段并进行数据读写操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近遇到需要把oracle里的部分数据导出到foxpro数据库里的事情。

 

方案一:把oracle导出到XSL里。再导入到foxpro里。

 

方案二:直接生成*.dbf文件。导入到foxpro里。

 

在网上找了一下。最后找到xBaseJ,开源项目。

 

package org.xBaseJ.test;
/**
 * xBaseJ - Java access to dBase files
 *<p>Copyright 1997-2007 - American Coders, LTD  - Raleigh NC USA
 *<p>All rights reserved
 *<p>Currently supports only dBase III format DBF, DBT and NDX files
 *<p>                        dBase IV format DBF, DBT, MDX and NDX files
*<p>American Coders, Ltd
*<br>P. O. Box 97462
*<br>Raleigh, NC  27615  USA
*<br>1-919-846-2014
*<br>http://www.americancoders.com
@author Joe McVerry, American Coders Ltd.
@version 2.2.0
*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library Lesser General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
*/


import java.io.IOException;

import org.xBaseJ.DBF;
import org.xBaseJ.xBaseJException;
import org.xBaseJ.fields.CharField;
import org.xBaseJ.fields.MemoField;

import junit.framework.TestCase;


public class testDBF extends TestCase {

	public void testBuildDBF() {
		DBF aDB = null;
		try {
			aDB = new DBF("testdbt.dbf", true);
		} catch (SecurityException e) {
			fail(e.getMessage());
		} catch (xBaseJException e) {
			fail(e.getMessage());
		} catch (IOException e) {
			fail(e.getMessage());
		}

		CharField cf = null;
		try {
			cf = new CharField("char", 10);
		} catch (xBaseJException e) {
			fail(e.getMessage());

		} catch (IOException e) {
			fail(e.getMessage());

		}
		MemoField mf = null;
		try {
			mf = new MemoField("memo");
		} catch (xBaseJException e) {
			fail(e.getMessage());

		} catch (IOException e) {
			fail(e.getMessage());
		}

		try {
			aDB.addField(cf);
		} catch (xBaseJException e) {
			fail(e.getMessage());
		} catch (IOException e) {
			fail(e.getMessage());
		}
		try {
			aDB.addField(mf);
		} catch (xBaseJException e) {
			e.printStackTrace();
			fail(e.getMessage());
		} catch (IOException e) {
			fail(e.getMessage());
		}

		try {
			aDB.close();
		} catch (IOException e) {
			fail(e.getMessage());

		}

		try {
			aDB = new DBF("testdbt.dbf");
			cf = (CharField) aDB.getField("char");
			mf = (MemoField) aDB.getField("memo");
			cf.put("123456789");
			mf.put("123456789");

			aDB.write();

			cf.put("9");
			mf.put("9");

			aDB.write();

			aDB.close();
		} catch (xBaseJException e) {
			fail(e.getMessage());
		} catch (IOException e) {
			fail(e.getMessage());
		}

		try {
			aDB = new DBF("testdbt.dbf");

			cf = (CharField) aDB.getField("char");
			mf = (MemoField) aDB.getField("memo");

			aDB.read();

			String s = cf.get();
			assertEquals("123456789", s);

			s = mf.get();
			assertEquals("123456789", s);

			aDB.read();

			s = cf.get();
			assertEquals("9", s);

			s = mf.get();
			assertEquals("9", s);

		} catch (xBaseJException e) {
			fail(e.getMessage());
		} catch (IOException e) {
			fail(e.getMessage());
		}

	}
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值