高手进。。文本文件怎么样导入到oracle数据库里面,条件是一定要通过java代码

fiona341 2008-09-26 02:48:45
如题。。。。请各位牛人帮帮忙啊。。告诉我个思路。。。不能用到sqlldr和第三方工具,
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxhjyh123 2008-09-27
  • 打赏
  • 举报
回复
其实好像在prepareStatement中个有个方法可以吧.prepareStatement.setCharacterStream()参数是可以
直接放流的。
watermarkmms 2008-09-27
  • 打赏
  • 举报
回复
public boolean saveData(List<String> fileList, String localPath)

throws Exception {
boolean b = false;
String p = config.getServletContext().getRealPath("/");
int yy = p.indexOf("default");
String f = p.substring(0,yy);
String str1;
String str2;
String str3;
String str4;
String str5;
String line;
Date sDate = new Date();
Calendar cl = Calendar.getInstance();
cl.setTime(sDate);
cl.add(Calendar.DAY_OF_YEAR,-1);
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String yesterday =fmt.format(cl.getTime());
String time = yesterday.substring(0,10);
String[] str = null;
Statement stm =null;
ResultSet rs=null;
try{
conn=DBUtils.getConnection();
stm =conn.createStatement();
conn.setAutoCommit(false);

for (int i = 0; i < fileList.size(); i++) {
FileInputStream fis = new FileInputStream(new File(localPath+ fileList.get(i)));
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
do {

line = br.readLine();
int x=0;
if (line != null) {
++x;
str = line.split(",");
str1 = str[0];
str2 = str[1];
str3 = str[2];
str4 = str[3];
str5 = time;

String sql = "insert into cm_ct_watermark_count values('"+str5+"','"+str2+"','"+str3+"','"+str4.substring(0,10)+"','"+str1+"')";

stm.execute(sql);
if(x%1000==0){
conn.commit();
}

}

} while (line != null);
conn.commit();
br.close();
isr.close();
fis.close();
}
b=true;
}catch(Exception e ){
e.printStackTrace();

}finally{
JdbcConnSource.close(rs, stm);
System.out.println("list close is ========");
DBUtils.closeConnection(conn);
System.out.println("conn close is ========");
}
return b;
}
刚写完的一个,和你的需求类似,我的文本是四个字段,用“,”隔开的,自己再添加个时间作为标记。我现在为了防止事务过大,做的是1000行提交一次。所以你要用这一段,还要加个错误处理,就是一旦中间步骤有一场,你要根据那个时间标记把本次的更新数据全部删除掉。
jsjlw 2008-09-26
  • 打赏
  • 举报
回复
如5楼所说解析文件..循环里面拼SQL,然后stmt.addBatch(sql);stmt.executeBatch();(ORACLE);

自己写吧.多练练.
fiona341 2008-09-26
  • 打赏
  • 举报
回复
有人有稍微详细点的代码吗。。我想研究一下。。。真的拜托各位了。。。。谢谢啊。。我L.V_cookie1024@hotmail.com,谢谢。。
yeah920 2008-09-26
  • 打赏
  • 举报
回复
读取文本文件:
FileInputStream fis=null;
InputStreamReader isr=null;
BufferedReader br=null;
try
{
File f=new File(filePathName);
if(!f.exists()||!f.isFile())
throw new FileNotFoundException();
fis=new FileInputStream(f);
isr=new InputStreamReader(fis);
br=new BufferedReader(isr);
while((line=br.readLine())!=null)
{
//接着把line再格式化,然后储存到list中.
}
}
.........
然后写sql语句,读取list中的内容insert到db.
liaoyi_ipanel 2008-09-26
  • 打赏
  • 举报
回复
我存过图片到数据库,没存过文本文件.
我处理文本文件都是先读出来,成字符串,再存到数据库的.
取的时候再写回文件中.
fiona341 2008-09-26
  • 打赏
  • 举报
回复
各位有没有类似的代码。。能让我看看吗!!研究一下。。急啊。。。。
tinsn 2008-09-26
  • 打赏
  • 举报
回复
写一个程序把文本文件中的记录顺序读出来,
然后写sql语句,把文本记录insert到数据库。
最原始的方法。
liaoyi_ipanel 2008-09-26
  • 打赏
  • 举报
回复
读取出里面的东西,存到数据库;取的时候再存回到文本文件中.

file-->String-->db;
db-->String-->file.

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧