Connecting Tech Pros Worldwide Help | Site Map

Extract BLOB from MySQL & save them anywhere in our pc

Newbie
 
Join Date: Nov 2006
Posts: 2
#1: Nov 30 '06
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.  
Newbie
 
Join Date: Nov 2006
Posts: 2
#2: Dec 3 '06

re: Extract BLOB from MySQL & save them anywhere in our pc


any1 there able to help? needed it badly..thanks ^^
Member
 
Join Date: Feb 2007
Posts: 43
#3: Feb 28 '07

re: Extract BLOB from MySQL & save them anywhere in our pc


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 )
Reply