-
Read file from database
Hello,
I´m new to java and new to this forum, so I hope you will be patience with me :)
What I´m trying to do is this:
I read a file from database, and I need to show this file directly to the user. This file is saved as Blob in Oracle database and I read it in this way:
String sql = "SELECT image FROM pictures ";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet resultSet = stmt.executeQuery();
File image = new File("D:\\java.gif");
FileOutputStream fos = new FileOutputStream(image);
byte[] buffer = new byte[1];
//
// Get the binary stream of our BLOB data
//
InputStream is = resultSet.getBinaryStream(1);
while (is.read(buffer) > 0) {
fos.write(buffer);
}
fos.close();
Now I need to "show" this file to the user but I have no clue how.
If you can suggest me...any idea will be welcome.
Thank you in adavnce.
-
Use a bigger buffer...that's just a suggestion by the way, and not how to show the picture.
What are you using as a front end?
Swing?