sullis      2005/01/15 15:35:32

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        DelegatingConnection.java
  Log:
  fixed NullPointerException in toString() method
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.20      +35 -1     
jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingConnection.java
  
  Index: DelegatingConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingConnection.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DelegatingConnection.java 6 Mar 2004 13:35:31 -0000       1.19
  +++ DelegatingConnection.java 15 Jan 2005 23:35:32 -0000      1.20
  @@ -79,6 +79,40 @@
           _conn = c;
       }
   
  +    public String toString() {
  +     String s = null;
  +     
  +     Connection c = this.getInnermostDelegate();
  +     if (c != null) {
  +             try {
  +                     if (c.isClosed()) {
  +                             s = "connection is closed";
  +                     }
  +                     else {
  +                             DatabaseMetaData meta = c.getMetaData();
  +                             if (meta != null) {
  +                                     StringBuffer sb = new StringBuffer();
  +                                     sb.append(meta.getURL());
  +                                     sb.append(", UserName=");
  +                                     sb.append(meta.getUserName());
  +                                     sb.append(", ");
  +                                     sb.append(meta.getDriverName());
  +                                     s = sb.toString();
  +                             }
  +                     }
  +             }
  +             catch (SQLException ex) {
  +                     s = null;
  +             }
  +     }
  +     
  +     if (s == null) {
  +             s = super.toString();
  +     }
  +     
  +     return s;
  +    }
  +
       /**
        * Returns my underlying [EMAIL PROTECTED] Connection}.
        * @return my underlying [EMAIL PROTECTED] Connection}.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to