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: [email protected]
        ReportedBy: [EMAIL PROTECTED]


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to