• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FileChooser.getSelected() turn into Blob

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a file chooser and I want to take the selected file, and turn it into a Blob so I can store it in a MySQL DB... Does anyone have any advice?

Note: I did look around previous forums and didn't find anythign quite liek this.

Here is a code snippit:



Thanks,
Michael
[ May 03, 2008: Message edited by: Scott Selikoff ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first half seems all right, but it is possible to shorten it when you have it working and can lose the testing code. Blob in Java is actually an interface, so it doesn't have a constructor.

It is some time since I wrote any SQL, but I think you are looking for an INSERT via your connection. You may be able to pass the File object directly to your connection. I can't see anything corresponding to BLOBs in the Java Tutorials here, but it is a nice introduction to SQL. A little detail about BLOBs for MySQL here.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun has BLOB examples in the JDBC 2.0 tutorial.

Note that they key is to pass the BLOB using preparedStatement.setBinaryStream() rather than setBlob().
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic