java读取txt文件,导入数据库

这篇博客展示了如何使用Java从TXT文件中读取数据,然后将这些数据批量导入到Oracle数据库中。通过建立数据库连接,使用PreparedStatement进行SQL插入操作,实现了数据的分批提交,提高了导入效率。

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

package com.egf.qingbao;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
* @author xh
* @version $Revision: 1.1 $
* @since 0.1
*/
public class CopyOfReadTxtutil {
private static Connection conn = null;

public static void readTxtFile(String filePath) {
conn = JdbcUtil.getConnection("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@xxx.x.x.xxx:1521:tjkf", "ypxx", "ypxx");
PreparedStatement pre = null;
String sql = "insert into yp_tldp values(SEQ_YP_TLDP.nextval,?,?,?,?,?,?,?,?,?,?,?)";
String encoding = "UTF-8";
long startTime = System.currentTimeMillis();
File file = new File(filePath);
if (file.isFile() && file.exists()) {
InputStreamReader read = null;
try {
read = new InputStreamReader(new FileInputStream(file),
encoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new Buffered
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值