Getting BLOB Data from a Database Table
A BLOB is a reference to data in a database.
This example demonstrates how to retrieves bytes from a BLOB.
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT col_blob FROM mysql_all_table");
if (rs.next()) {
// Get the BLOB from the result set
Blob blob = rs.getBlob("col_blob");
// Get the number bytes in the BLOB
long blobLength = blob.length();
// Get bytes from the BLOB in a byte array
int pos = 1; // position is 1-based
int len = 10;
byte[] bytes = blob.getBytes(pos, len);
// Get bytes from the BLOB using a stream
InputStream is = blob.getBinaryStream();
int b = is.read();
}
} catch (IOException e) {
} catch (SQLException e) {
}
Hi Sir, I am Sunraj. Your Code helped me a lot. After trying for two three hours. Your code gaved me a solution to retrieve the file from db...
what did you use in the design to retrieve your image? eg. jlabel, jtextfield, etc.?
HI,I am creating a blob to save an image from the JAVA.. Now i want to Display that image how can do that? Thanks and Regards.
hello friend, i can't retrive blob field value from a table...
geneal error comes...
plz help me....
When retreiving binary data from db, using resultset.getBinaryStream(), result data is appended with some extra characters..
How to display the byte data to excel file using JSP, could you please help me here?
I am retrieveing a TreeMap from Oracle db. above lines are okay but how will i get the treemap again in treemap type after storing it as seialized in db?
This is right but how to display image on page