By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,123 Members | 548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,123 IT Pros & Developers. It's quick & easy.

Extract BLOB from MySQL & save them anywhere in our pc

P: 2
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

Expand|Select|Wrap|Line Numbers
  1.  try { 
  2. Statement stmt = connection.createStatement();
  3. ResultSet rs = stmt.executeQuery("SELECT blob_data FROM mysql_data_table");
  5. if ( {
  6. // Get the BLOB from the result set
  7. Blob blob = rs.getBlob("blob_data");
  9. // Get the number bytes in the BLOB
  10. long blobLength = blob.length();
  12. // Get bytes from the BLOB in a byte array
  13. int pos = 1; // position is 1-based
  14. int len = 10;
  15. byte[] bytes = blob.getBytes(pos, len);
  17. // Get bytes from the BLOB using a stream
  18. InputStream is = blob.getBinaryStream();
  19. int b =;
  20. }
  21. } catch (IOException e) {
  22. } catch (SQLException e) {
  23. }
Nov 30 '06 #1
Share this Question
Share on Google+
2 Replies

P: 2
any1 there able to help? needed it badly..thanks ^^
Dec 3 '06 #2

P: 43

Can you tell me how to retrieve BLOBs from mysql ?
I worked on this for weeks, but found little information about this....
it is very important for me now.

Thank you very much
Looking forward to your reply

my email is :[Removed by moderator (against site rules)]

Xiaohui Li ( Tanya )
Feb 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.