Log4J JDBCAppender

Hi!

I'm extending the org.apache.log4j.jdbc.JDBCAppender to log my web application directly in a database.

OK, this is my code:

package dbweb.logging;

import java.sql.*;

import javax.sql.*;

import java.util.*;

import javax.naming.*;

publicclass JDBCAppenderextends org.apache.log4j.jdbc.JDBCAppender{

private InitialContext context;

private ResourceBundle webappconf;

private String admindb;

private DataSource datasource;

public JDBCAppender(){

super();

try{

context =new InitialContext();

// Get ConnectionPool

datasource = (DataSource) context.lookup("comp/env/jdbc/MyConnectionPool");

}catch (javax.naming.NamingException nEx){

System.out.println(nEx.getExplanation());

}

}

protected Connection getConnection(){

try{

connection = datasource.getConnection();

connection.getAutoCommit();

return connection;

}catch (SQLException sqlEx){

System.out.println(sqlEx.getMessage());

returnnull;

}

}

protectedvoid closeConnection(Connection con){

try{

con.close();

}catch (SQLException sqlEx){

System.out.println(sqlEx.getMessage());

}

}

protected String getLogStatement(org.apache.log4j.spi.LoggingEvent event){

// MAKE STATEMENT

// ...

return sqlStatement;

}

}

When I try to get my web application ConnectionPool it seems that the JDBCAppender InitialContex isn't the web application one, in fact this command:

datasource = (DataSource) context.lookup("comp/env/jdbc/MyConnectionPool");

returns null, therefore all my application crashes when I try to log a message. This is the error:

No object bound to name java comp/env/jdbc/MyConnectionPool

How can I do to get my web application Connection Pool?

Thanks in advance.

+ Anhur +

[3648 byte] By [Anhura] at [2007-10-1 17:30:30]
# 1
Hi,Did u get a solution for your questions. i am having the same problem.. ThanksDevi
devi_sreea at 2007-7-11 2:22:35 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2
Try adding "java:" before "comp".
vinays84a at 2007-7-11 2:22:35 > top of Java-index,Archived Forums,Debugging Tools and Techniques...