You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Bender Heri <HB...@Ergonomics.ch> on 2005/05/02 13:46:25 UTC

RE: Query regarding Stored Procedure / Insertion Into Multiple Tables

Hi Rajesh

it's no problem to use a stored proc, at least not if the DB is Oracle.

I have a descendent of JDBCAppender: myJDBCAppender. This class has a property PreparedSQL, which is filled by the LogManager when initializing from configuration file (see below). 

Within the overwritten execute method you must bind the ?-parameters to the passed values. You get these values by parsing the sql-String which is passed by the caller of the method, and which is the converted pattern. Therein are @@ used as delimiters of the values. Something like that:

        StringTokenizer tokenizer = new StringTokenizer( aSql, "@@" );

        int i = 3;
        while ( tokenizer.hasMoreTokens() )
        {
            String token = tokenizer.nextToken().trim();
            switch ( i )
            {
                case 4 : // level. We have to convert the string into the level number
                    myCstmt.setInt( i, Level.toLevel( token ).toInt() );
                    break;
                default :
                    myCstmt.setString( i, token );
                    break;
            }
        
            i++;
        }



The definition in Log4J.xml:

    <appender name="DB_APPENDER" class=".....myJDBCAppender">
        <param name="PreparedSQL" value="{ ? = call INS_LOG( ?, ?, ?, ?, ?, ? ) }"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%F:%L@@%-5p@@%-10X{category}@@%-7t@@%m"/>
        </layout>
        ....(filters)   
    </appender>


Hope this helps.

Heri





> -----Original Message-----
> From: Rajesh [mailto:raj694@yahoo.com]
> Sent: Friday, April 29, 2005 2:28 PM
> To: log4j-user@logging.apache.org
> Subject: Query regarding Stored Procedure / Insertion Into Multiple
> Tables
> 
> 
> Hi there,
>  
> I'm using the original JDBCAppender - the one included in the 
> log4j jar. I intend to insert i nto multiple tables using the 
> same. I have been searching real hard but haven't come to 
> know as to how it can be done.
>  
> I have come across many postings asking the same but no 
> response as yet. One such posting says "Yes, it can be done", 
> i mean, using a stored procedure with sql param of 
> JDBCAppender. Is it possible?
>  
> Can the existing JDBCAppender be used to insert data into a 
> database using a stored procedure?
>  
> There is this Danko Mannhaupt's JDBCPlusAppender that claims 
> to do that and is available on net.
> -- Is it safe to use?
> -- Does it need to be used with the existing log4j 1.2.9 jar? 
> What all configuration would be reqd?
>  
> Any kind of help would be highly appreciated.
>  
> Thanks,
> Rajesh
> Pune, India
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 

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