excel文件导入 oracle 中的blob字段中,再从库中导出成文件发生的问题
我将excel文件导入到oracle数据库中的Blob字段下,再从库中将数据读出写成文件,但是打开文件后提示说,格式不对,我再讲excel以记事本打开,和原文件对比,发现...
我将excel文件导入到oracle数据库中的Blob字段下,再从库中将数据读出写成文件,但是打开文件后提示说,格式不对,我再讲excel以记事本打开,和原文件对比,发现数据明显不一样了,但是txt,图片之类的数据文件操作正常,求教这是何原因!
以下是上传到数据库的代码,发现传进数据库里的EXCEL数据与原数据不一样了。
public static void main(String[] args) throws Exception {
Class.forName(drive);
Connection con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(false);
Statement st = con.createStatement();
st.executeUpdate("insert into t_file values('" + fileName + "',empty_blob())");
ResultSet rs = st.executeQuery("select file_blob from t_file where filename = '" + fileName + "' for update");
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
OutputStream outStream = blob.getBinaryOutputStream();
File file = new File(path);
InputStream fin = new FileInputStream(file);
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ((len = fin.read(b)) != -1) {
outStream.write(b, 0, len);
blob.putBytes(1, b);
}
fin.close();
outStream.flush();
outStream.close();
}
con.commit();
con.close();
} 展开
以下是上传到数据库的代码,发现传进数据库里的EXCEL数据与原数据不一样了。
public static void main(String[] args) throws Exception {
Class.forName(drive);
Connection con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(false);
Statement st = con.createStatement();
st.executeUpdate("insert into t_file values('" + fileName + "',empty_blob())");
ResultSet rs = st.executeQuery("select file_blob from t_file where filename = '" + fileName + "' for update");
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
OutputStream outStream = blob.getBinaryOutputStream();
File file = new File(path);
InputStream fin = new FileInputStream(file);
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ((len = fin.read(b)) != -1) {
outStream.write(b, 0, len);
blob.putBytes(1, b);
}
fin.close();
outStream.flush();
outStream.close();
}
con.commit();
con.close();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询