Application using JDBC - design advice

Hi all,

I am building an application that using JDBC, connects to an Informix database (using the Openlink JDBC drivers) in specific intervals, extracts some data, put them in a file and then send them using ftp.

I am using Timer and TimerTask to implement the intervals. So every 30 minutes i call a TimerTask that runs a for loop in order to execute 12 different SELECT statements and thus create 12 different files.

The way i have implemented the JDBC connection is that for every run in the for loop, i create a new object of a Class that has code for the connection to the db, i execute the select stmt, get the ResultSet, create the file, send it and then close the connection to the ftp server and the connection to the database (using the DBobject.close() method) .

My question is if this way is good programming practice or should i change to something else. For example i was thinking to create a class that provides the connection and the ResultSet from static methods taking as an argument the query and returning the ResultSet so i don't have to create many objects every 30 minutes.

Can you please advice on my questions and provide any other practices are good for this design?

[1231 byte] By [gvagenasa] at [2007-11-27 9:03:02]
# 1

Sounds like a Mickey-Mouse-Program - do nothing more for budget reason.

In general, if you need a connection more often than now (activity each 30 min is nearly dead ;-) you should think about a connection pool, performing task of getting the connection.

Instead of the TimerTask you can take a look at the Quartz Tool. an open source tool for perfomring tasks with defined triggers

Sucharda at 2007-7-12 21:34:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Suchard,

Thanks for the reply. I've already took a look at the Quartz tool which is a really powerful scheduling tool but i think the TimerTask is enough for what i need to do. My problem was more on the issue of the connection to the database and the performance of the application. I will take a look in the connection pool you mention.

Any other advice is welcome.

Thanks

George

gvagenasa at 2007-7-12 21:34:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...