By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,558 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,558 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");
  4.  
  5. if (rs.next()) {
  6. // Get the BLOB from the result set
  7. Blob blob = rs.getBlob("blob_data");
  8.  
  9. // Get the number bytes in the BLOB
  10. long blobLength = blob.length();
  11.  
  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);
  16.  
  17. // Get bytes from the BLOB using a stream
  18. InputStream is = blob.getBinaryStream();
  19. int b = is.read();
  20. }
  21. } catch (IOException e) {
  22. } catch (SQLException e) {
  23. }
  24.  
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
hi,

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.