473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Extract BLOB from MySQL & save them anywhere in our pc

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
2 6471
Vinciz
2
any1 there able to help? needed it badly..thanks ^^
Dec 3 '06 #2
tanyali
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

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

Similar topics

7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
4
by: Luis | last post by:
Hi, I can a big problem... because I have a byte data = new byte, and I need to save this to a field on my MySQL database (here I have a BLOB field) but ¿can I save it? because if I put: Insert...
3
by: Selen | last post by:
I would like to be able to extract a BLOB from the database (SqlServer) and pass it to a browser without writing it to a file. (The BLOB's are word doc's, MS project doc's, and Excel spreadsheets....
1
by: Markusek Peter | last post by:
Hi, I'm using MySQLDriverCS. I've got no problem to store BLOB into database, but I can't get it back(save to file). Problem is with DataTable(returns string:( ) My code: -- DataTable dt = new...
2
by: pmz | last post by:
Dear Group, I'm connecting in C# with remote (BSD) MySQL server with ODBC Driver, and I'm trying to find the best sollution in such problem: As I've read on MySQL manual, they have suggested...
0
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I...
4
by: carlbernardi | last post by:
Hi, I have a question about the size of a blob if it indeed needs to be set and cannot be variable. I ask this question because I am trying to save web pages to a database but a web page can be...
1
by: waleedmazhar | last post by:
Hello Everybody Can anybody tell me when to save images in mysql blob and when save image folder and save the image name in database. which is more better saving image into database or save it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.