You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Raymond DeCampo <rd...@twcny.rr.com> on 2003/05/06 05:01:09 UTC

Prepared Statement Appender

All,

I am attaching my first go at a JDBC appender that uses 
PreparedStatements.  It's not totally ready, in particular it needs more 
javadoc and formatting, but I think it is close enough to get some 
feedback on.

The PreparedStatementAppender is the main class.  There are interfaces 
for obtaining the Connection (ConnectionSource) and obtaining the 
PreparedStatement (PreparedStatementSource) itself.  If the 
PreparedStatementSource is not defined then the appender will create the 
SQL itself based on the configuration.  I have implemented a 
UrlConnectionSource that gets the Connection in tradition JDBC fashion. 
  I plan to implement a DataSourceConnectionSource as well that gets the 
connections from a DataSource obtained via JNDI from an application server.

Within the jar I have attached a sample program and a sample 
configuration file.  I ran the test against MySQL on linux with the 
following table defined:

mysql> desc LOG4J;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| msg       | blob         | YES  |     | NULL    |       |
| logger    | varchar(255) | YES  |     | NULL    |       |
| level     | varchar(5)   | YES  |     | NULL    |       |
| ndc       | varchar(255) | YES  |     | NULL    |       |
| exception | blob         | YES  |     | NULL    |       |
| stack     | blob         | YES  |     | NULL    |       |
| formatted | blob         | YES  |     | NULL    |       |
| stamp     | datetime     | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+

One area that could use a little inspiration is where I have one 
parameter instance field for each piece of data on the LoggingEvent.  I 
couldn't think of a better way without using reflection.  If anyone has 
any suggestions I would appreciate them.

Actually, I would appreciate any feedback in general...

Thanks,
Ray


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Re: Prepared Statement Appender

Posted by Raymond DeCampo <rd...@twcny.rr.com>.
That's the second time today I've forgotten an attachment...