Question

For a university assignment I have been assigned I have a Prize object which contains either text, image, or video content. I would like to persist this information into a BLOB field within an Apache Derby database (which will be running on a low powered PDA). How can I add this data to the database?

Thanks in advance.

Was it helpful?

Solution

In this article Five Steps to Managing Unstructured Data with Derby you can read how to do this.

It describes how to insert binary data into a column with the BLOB datatype in Apache Derby using JDBC.

OTHER TIPS

I assume you'll be connecting via JDBC. If so, simply write your SQL and look at the setBlob method of a PreparedStatement. Should be pretty straightforward.

Serialization is the easy way to do it, however if possible you could make it look like a real database table with a structure containing id (bigint), datatype (smallint), creationdate (date) and data (blob) and specifically make the client code to save the object's data there. This way you could do searches like "get all video prizes created between January 1st 2008 and January 15th 2009" and it wouldn't break down old data if your class would change too much for the serialization to stop working.

This sort of solution would be easy to extend in the future too if there would be need for it; I understand this is a school assignment and such need most likely won't ever surface but if your teacher/professor knows his stuff, I bet he's willing to give an extra point or two for doing this excercise in this way since it takes a bit more time and shows that you can take the steps to prepare in advance for coping in the everchanging landscape of software development.

If you are using Netbeans (I assume Eclipse has similar functionality) you can setup your database schema and the create new Java entity classes from the database and it will generate the appropriate JPA classes for you.

http://hendrosteven.wordpress.com/2008/03/06/simple-jpa-application-with-netbeans/

This is nice as it allows you to focus on your code rather than the database glue code.

The best solution , is to use Derby, because it keep being a multi platform app developed via Java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top