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 Jon Wilmoth <JW...@starbucks.com> on 2002/06/05 23:41:08 UTC

Log4j JDBCAppender

What's the quickest/simplest way to filter out quotes from the pattern
layout conversion character values?  I'm currently getting errors trying to
insert the thread (%t) because weblogic produces a string like so:

ExecuteThread: '13' for queue: 'default'

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Log4j JDBCAppender

Posted by Ben Sandee <tb...@pobox.com>.
Kevin Steppe wrote:

> Jon,
>    Please post to the users list only for this kind of question.  Now 
> to answer your question:
>
> try:
> sql=insert into logtable (threads) values ("%t")
>
> For most databases you can use either ", or ', for varchar fields.  
> Use the one not in the value.  If both are in the value you have to do 
> escaping.  As far as I can tell the JDBC version in JDK1.3.1 does not 
> have a generic escape call.  If I'm wrong, someone please tell me so I 
> can get that into the JDBCAppender.

Kevin,

Ideally the appender would support the optional use of PreparedStatement 
objects, rather than building SQL strings dynamically.  With a 
PreparedStatement there is no need to escape any text values.  For example:

PreparedStatement st = conn.prepareStatement("insert into logtable 
(threads) values (?)");
try
{
    st.setString(1, "I can put single quotes ' and double quotes \" in 
this text");
    st.executeUpdate();
}
finally
{
    st.close();
}

I believe this would take some reworking of the current JDBCAppender, 
however, due to the fact that simple text replacements cannot be used. 
 Instead there would have to be some way to associate a the integer 
parameter index with a piece of data (%t or whatever).

BTW, I don't actually use the JDBCAppender myself -- that's my 
view-from-the-outside.

Ben



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Log4j JDBCAppender

Posted by Benedetta Barbieri <bb...@dianoema.it>.
I solved my problem! Forget about my mail

Benedetta

-----Original Message-----
From: Kevin Steppe [mailto:ksteppe@pacbell.net]
Sent: giovedi 6 giugno 2002 9.08
To: Log4J Users List
Subject: Re: Log4j JDBCAppender


Jon,
    Please post to the users list only for this kind of question.  Now
to answer your question:

try:
sql=insert into logtable (threads) values ("%t")

For most databases you can use either ", or ', for varchar fields.  Use
the one not in the value.  If both are in the value you have to do
escaping.  As far as I can tell the JDBC version in JDK1.3.1 does not
have a generic escape call.  If I'm wrong, someone please tell me so I
can get that into the JDBCAppender.



Jon Wilmoth wrote:

>What's the quickest/simplest way to filter out quotes from the pattern
>layout conversion character values?  I'm currently getting errors trying to
>insert the thread (%t) because weblogic produces a string like so:
>
>ExecuteThread: '13' for queue: 'default'
>
>--
>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>







--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Log4j JDBCAppender

Posted by Kevin Steppe <ks...@pacbell.net>.
Jon,
    Please post to the users list only for this kind of question.  Now 
to answer your question:

try:
sql=insert into logtable (threads) values ("%t")

For most databases you can use either ", or ', for varchar fields.  Use 
the one not in the value.  If both are in the value you have to do 
escaping.  As far as I can tell the JDBC version in JDK1.3.1 does not 
have a generic escape call.  If I'm wrong, someone please tell me so I 
can get that into the JDBCAppender.



Jon Wilmoth wrote:

>What's the quickest/simplest way to filter out quotes from the pattern
>layout conversion character values?  I'm currently getting errors trying to
>insert the thread (%t) because weblogic produces a string like so:
>
>ExecuteThread: '13' for queue: 'default'
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>