Tuesday, December 21, 2004

Šťastné a veselé!

Here in Slovakia we say Šťastné a veselé! as Christmas greeting. And as my small gift, here is just another HolidayCalendar.java class and its descendants:

You will also need AgeCalculator.java to compile the above sources.

And here is the documentation.

Enjoy!

Thursday, December 16, 2004

An Image in a BLOB (Part 2 - GUI Tester)

I wrote a very simple, ugly (Swing :-)), but functional GUI for my new BlobImage.java class.

JImage

There is more than write one class for the app, so here is the whole archive jarred. Note that you must have the Firebird JDBC / JCA driver in your classpath. Create the database using images.sql from the archive, run java -jar jimage.jar, and when the application starts, adjust the database URI in the Login Dialog. Enjoy! (or rewrite :-))

Wednesday, December 15, 2004

An Image in a BLOB (How To)

Do you like storing images in SQL database BLOBs? I love it... :-)

Long time ago I wrote a simple Delphi app which stored images in a Firebird SQL database. My database is still there, but I don't have Delphi anymore... :-)

So, I tried to do it in Java using Firebird's JayBird JDBC/JCA driver. The documentation provides two examples on how to insert data to a BLOB column in a table and how to load them back, but I couldn't make the examples compile with Java 2 SDK 1.4.2_05. As a true Java newbie I derived a new class BlobImage.java right from the java.lang.Object, added some code.... Maybe you'll find it useful.

Note that you will need BlobContentType interface, too. Finally, there is a javadoc for the class.

Monday, December 13, 2004

SAX Parser Problem (Very Odd)

While implementing a simple SAX parser for Open Financial eXchange, a XML scheme in which my bank provides account statements I found the following problem with the parser:

Some of the transaction amounts read from the XML file got truncated. For example, when the parser reads the following XML fragment:
<trnamt>1770.28</trnamt>
it would truncate the value to 177 and you would have 177$ instead of 1770.28$. Very odd :-(

Later, I found the above problem in forum.java.sun.com

The solution can be found (as usually) in the documentation for the characters() method of org.xml.sax.ContentHandler. Did you read it? :-)

"SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks..."

So, here comes my code, AbstractOFXHandler.java and documentation.