【发布时间】:2014-07-25 09:04:52
【问题描述】:
我在 LONG 类型列中有一个存储的 Files @ Oracle DB。 现在我需要打开它而不制作相同的文件。怎么做?
在 Eclipse 工作场所制作文件的示例代码。如何调整它不在文件系统中制作文件?
感谢您的回答!保证正确答案!
session.doWork(new Work() {
public void execute(Connection connection) throws SQLException {
String sql = (" SELECT failas,aprasymas,ispletimas FROM ZALA.claims_additional_doc_v where id = ? ");
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = connection.prepareStatement(sql);
stmt.setLong(1, papId);
rs = stmt.executeQuery();
if (rs.next()) {
byte[] bytes = rs.getBytes(1);
String fileName = rs.getString(2);
// String fileType = rs.getString(3);
FileOutputStream fileO = null;
String userHomeFolder = System.getProperty("user.home") + "\\Downloads";
try {
fileO = new FileOutputStream(userHomeFolder + "\\" + fileName);
fileO.write(bytes);
fileO.close();
File file = new File(userHomeFolder + "\\" + fileName);
if (Desktop.isDesktopSupported()) {
try {
if (file.toString().endsWith(".pdf"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
else {
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
}
} catch (IOException ex) {
log.debug("err @ runtime" + ex.getMessage());
}
}
} catch (Exception e) {
String err = e.toString();
log.debug("err @ stream" + err);
} finally {
if (fileO != null) {
fileO.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
new DisnetErrorHandler().handleError(e);
}
SaveUtility.closeRsAndStmt(rs, stmt);
}
});
【问题讨论】:
-
问题是什么?您想读取存储在数据库中的文件内容吗?你想在不创建文件的情况下写入文件(这会很奇怪)吗?使用后要删除文件吗?您的问题和代码似乎不一致。
-
我想从数据库中读取文件并以正确的方式打开? Buisnes priview 是我得到了带有文件名的表,用户选择文件并打开它。文件可以是图像 pdf utc。
-
您打算如何使用文件数据?您是否通过 InputStream 访问它?还是直接通过java.io.File?我们需要更多细节。
-
只打开文件查看。用户可以在本地保存文件,然后根据需要上传...
-
@Speakwithsystem:如果您仅想打开文件以供查看,那么您为什么还要保存它(顺便说一句,您的问题不是说您不想创建文件)。为什么要上传刚刚从服务器检索到的文件?
标签: java file file-upload file-io