473,756 Members | 9,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract BLOB from MySQL & save them anywhere in our pc

2 New Member
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 6533
Vinciz
2 New Member
any1 there able to help? needed it badly..thanks ^^
Dec 3 '06 #2
tanyali
43 New Member
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
11484
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 convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
3
4726
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 2Mb) are stored in BLOB column. The amount of documents for the first year should not exceed 5/6 Giga, but I cannot make prevision for the next years. Those documents are mainly just accessed (update and delete are not so
4
3002
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 into archiv(ref, databinary) VALUES('"+ref+"', '"+ data+"') In my Database only save "System.byte" Can Someone help me?
3
3809
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. How can I do this?
1
8711
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 MySQLSelectCommand(...; //select that row and column where is BLOB string dest = Server.MapPath("image.jpg"); FileStream binFile = new
2
9001
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 table design including the BLOB-Fieldtype size in UInt64, where they've stored, while inserting, the size of inserted BLOB data. But in the matter of fact, I'm interested if it's necessary to include in table this integer field? Is there any way...
0
2412
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 can't save the jpg file as a BLOB field using this Method (I'm calling a Stored Procedure): Private Sub save_BLOB(ByVal Photo As Byte())
4
68843
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 anywhere from 10 characters to 200,000 characters and using blob(200000) is very inefficient. I was thinking of using various size tables ready for various size pages but I would be easier to manage having them all in one table.
1
1875
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 name into database and image itself into folder.
0
9117
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.