Required: Example on how to insert a file in a Blob field

46 views
Skip to first unread message

mauro.reg...@gmail.com

unread,
Nov 28, 2013, 3:56:04 AM11/28/13
to sqlit...@googlegroups.com
Hi everyone,

I'm just trying to use the Sqlite4java wrapper to SQLite.
It's quite powerful and really speedy, but the documentation behind it is not so good.
I can easily read and write values in the tables of a db, but I can't really understand how to insert a simple file (i.e. a JPEG picture) in a Blob field.
Is there anybody out there that can show me a complete working example on how to do it using Sqlite4java?

Thanks in advance!

Mauro

PS: I know a lot of people is telling me to put the reference of the file in a table field and let the file exist outside the db, in the filesystem, but what I'm trying to do is to have a single, portable file to distribute across a number of PC ...

ser...@almworks.com

unread,
Dec 2, 2013, 6:31:32 PM12/2/13
to sqlit...@googlegroups.com

Hi Mauro,

 

If your files fit in memory completely – I assume most pictures would – then there’s nothing special about inserting a blob. Prepare an SQLiteStatement with INSERT and bind a blob using SQLiteStatement.bind(int index, byte[] data), and execute. For extracting data, you’d use columnBlob() method.

 

If your blobs are really large, you can use SQLiteConnection.blob() method for incremental access, but that’s trickier.

 

Sorry if documentation is lacking. Feel free to contribute your article – we can post it to the project wiki.

 

Hope this helps!

Igor

--
You received this message because you are subscribed to the Google Groups "sqlite4java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlite4java...@googlegroups.com.
To post to this group, send email to sqlit...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlite4java.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages