I have a stored Files @ Oracle DB at LONG type column. Now i need to open it without making the same file. How it can be done ?
Sample code who makes the file at Eclipse workplace. How to adjust it do not making File at file system ?
Thanks for answers! The right answers guaranteed!
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);
}
});