hi guys... im new in java and i would love to learn some of these...
basically i got a sample code to retrieve the blob from the mysql.
however, i dont really know what to do with these retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the blob rite? Any idea/code/links on how to do it? kinda confuse.. thanks in advance
- try {
-
Statement stmt = connection.createStatement();
-
ResultSet rs = stmt.executeQuery("SELECT blob_data FROM mysql_data_table");
-
-
if (rs.next()) {
-
// Get the BLOB from the result set
-
Blob blob = rs.getBlob("blob_data");
-
-
// 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) {
-
}
-