【发布时间】:2013-12-26 09:08:07
【问题描述】:
我正在从 Oracle 数据库读取 blob 数据并将其写入文本文件。我的数据库中有两列名为 Number & system。我的表中有 100 个计数。但只有最后一行写在我的文本行中。下面是我尝试过的代码。
rs =stmt.executeQuery("select Number, system from system");
Blob lob = null;
while (rs.next()) {
String RECID = rs.getString(1);
System.out.println("Number"+ Number);
lob=rs.getBlob("system");
byte[] bdata = lob.getBytes(1, (int) lob.length());
String text = new String(bdata);
System.out.println("text"+ text);
System.out.println("rs value"+ lob);
String test=null;
test=RECID+":"+text;
FileOutputStream fos = new FileOutputStream("C:/DataRead/system.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes(test);
dos.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
在文本文件中,我得到了第 100 条记录,只有其他 99 行没有写入。
【问题讨论】:
-
您在每次迭代时重新打开输出文件,肯定会清除以前的版本。
-
感谢 Alexis,请建议如何打开每个迭代的输出文件