logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 42870] New: - DBAppender omits RETURN_GENERATED_KEYS, NullPointerException
Date Thu, 12 Jul 2007 14:03:28 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42870>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42870

           Summary: DBAppender omits RETURN_GENERATED_KEYS,
                    NullPointerException
           Product: Log4j
           Version: 1.3alpha
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: richard.landers@ct.gov


DBAppender.append(..) calls prepareStatement(..) without specifying the
Statement.RETURN_GENERATED_KEYS flag, even when the connection is known to
support the method getGeneratedKeys().

On DB2 v9 with JDBC type 4 driver (com.ibm.db2.jcc.DB2Driver) at least, this
causes a NullPointerException later on when DBAppender tries to read the
generated key.  When the flag is not specified, the ResultSet returned from
getGeneratedKeys() is null.  NPE at DBAppender.java line 267.

Existing bug: 37349 "DBAppender not working with jTDS driver" seems to have the
same root cause.

Here's a code snippet that fixes the problem for me:

  protected void append(LoggingEvent event) {
      Connection connection = null;
      try {
          connection = connectionSource.getConnection();
          connection.setAutoCommit(false);
          
          PreparedStatement insertStatement;
          if (cnxSupportsGetGeneratedKeys) {
              insertStatement = connection.prepareStatement(
                  insertSQL, Statement.RETURN_GENERATED_KEYS);
          } else {
              insertStatement = connection.prepareStatement(insertSQL);
          }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message