How to retrieve a blob field from MySQL table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lionelm2007
    New Member
    • Dec 2007
    • 10

    #1

    How to retrieve a blob field from MySQL table?

    I have a longblob field in a table that stores pics and other files. I am developing a Java application that needs to retrieve the files from the database and view them. I know that the longblob fields are binary data. Could you please provide me with some sample code that will at least retrieve the file from the database and save it on the user's hard disk?

    If there is a way to store a file as blob, then there should be a way to retrieve it!

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    From MySQL's point of view, fetching BLOB data is done in exactly the same way as all the other data types... with a SELECT query:
    [code=mysql]SELECT `blobField` FROM `myTable`[/code]
    The result of that will then be piped through whatever connection you used to execute the query.

    I'm not much of a Java coder myself, so I can't really comment on how Java would handle the return data, but I would imagine it is either returned as a string or a byte array.

    I suggest you ask in the Java forum for details, or look through the documentation for your MySQL connector class.
    (As I understand it, Java has excellent documentation)

    Comment

    Working...