我已经尝试使用 CSVWriter 将数据库表导出为 CSV。
但是我的表包含 BLOB 数据。如何将它们包含在我的导出中?
稍后,我将使用 CSVReader 导入导出的 CSV。有人可以分享一些概念吗?
这是我导出代码的一部分
ResultSet res = st.executeQuery("select * from "+db+"."+obTableNames[23]);
int colunmCount = getColumnCount(res);
try {
File filename = new File(dir,""+obTableNames[23]+".csv");
fw = new FileWriter(filename);
CSVWriter writer = new CSVWriter(fw);
writer.writeAll(res, false);
int colType = res.getMetaData().getColumnType(colunmCount);
dispInt(colType);
fw.flush();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
最佳答案
你看过encodeBase64String(byte[] data
)吗?方法来自 Base64
由 Apache 提供?
Encodes binary data using the base64 algorithm but does not chunk the output.
这应该允许您返回表示二进制大对象的编码字符串并将其合并到您的 CSV 中。
另一边的人可以使用 decodeBase64String(String data)
再次取回 BLOB。
关于java - 使用 CSVWriter 导出带有 BLOB 的数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12108934/