wood burning stoves 2.0*
The moose likes JDBC and the fly likes FileChooser.getSelected() turn into Blob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "FileChooser.getSelected() turn into Blob" Watch "FileChooser.getSelected() turn into Blob" New topic

FileChooser.getSelected() turn into Blob

Michael Paul

Joined: Mar 29, 2008
Posts: 14
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:

[ May 03, 2008: Message edited by: Scott Selikoff ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38075
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.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30138

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().

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: FileChooser.getSelected() turn into Blob
Similar Threads
JFileChooser problems
drawing to the file with GDC
How to open a file using Java
how to open picture in JPanel
JFileChoosers and file extensions