dbf文件mysql_dbf文件数据导入到mysql

本文介绍了两种方法将dbf文件数据导入到MySQL,包括直接使用insert语句和通过写入txt文件利用LOAD DATA INFILE命令。重点展示了如何创建DBFReader类来读取dbf文件,并提供了相关异常处理的代码示例。
摘要由CSDN通过智能技术生成

思路:

1、将dbf文件数据读出后,在用insert语句插入。效率太低,所以舍弃

2、将dbf文件数据写入txt文件中,然后用LOAD DATA INFILE 直接导入到数据库中

具体代码:

1、创建一个DBFReader

import java.io.DataInputStream;

import java.io.EOFException;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FilterInputStream;

import java.io.IOException;

import java.io.InputStream;

public class DBFReader

{

private DataInputStream stream = null;

private JDBField[] fields = null;

private byte[] nextRecord = null;

public DBFReader(String paramString)

throws

com.svcon.jdbf.JDBFException

{

try

{

init(new FileInputStream(paramString));

}

catch

(FileNotFoundException localFileNotFoundException)

{

throw new

com.svcon.jdbf.JDBFException(localFileNotFoundException);

}

}

public DBFReader(InputStream

paramInputStream)

throws

com.svcon.jdbf.JDBFException

{

init(paramInputStream);

}

private void init(InputStream

paramInputStream)

throws

com.svcon.jdbf.JDBFException

{

try

{

this.stream = new DataInputStream(paramInputStream);

int i = readHeader();

this.fields = new JDBField[i];

int j = 1;

for (int k = 0; k < i; ++k)

{

this.fields[k] = readFieldHeader();

j += this.fields[k].getLength();

}

if (this.stream.read() < 1)

throw new com.svcon.jdbf.JDBFException("Unexpected end of file

reached.");

this.nextRecord = new byte[j];

try

{

this.stream.readFully(this.nextRecord);

}

catch (EOFException localEOFException)

{

this.nextRecord = null;

this.stream.close();

}

}

catch

(IOException localIOException)

{

throw new com.svcon.jdbf.JDBFException(localIOException);

}

}

private int readHeader()

throws

IOException, com.svcon.jdbf.JDBFException

{

byte[]

arrayOfByte = new byte[16];

try

{

this.stream.readFully(arrayOfByte);

}

catch

(EOFException localEOFException1)

{

throw new com.svcon.jdbf.JDBFException("Unexpected end of file

reached.");

}

int i =

arrayOfByte[8];

if (i

< 0)

i += 256;

i += 256

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值