commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 9850] New: - No way to get at SQLException if connection to database fails in DriverManagerConnectionFactory
Date Thu, 13 Jun 2002 20:23:52 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9850>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9850

No way to get at SQLException if connection to database fails in DriverManagerConnectionFactory

           Summary: No way to get at SQLException if connection to database
                    fails in DriverManagerConnectionFactory
           Product: Commons
           Version: Nightly Builds
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Dbcp
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: fuerth@sqlpower.ca


We're using the Commons DBCP for a project which uses l10n for error messages.  As such, we
need access to the SQLException error code when connection fails.

This patch to apply the "root cause" design pattern (as seen in ServletException, JspException,
and InvocationTargetException of the official java API) works well for us.  We'd like to see
it included in future revisions of DBCP.

Thanks!

------- BEGIN DIFF
diff -c -r1.2 DriverManagerConnectionFactory.java
*** DriverManagerConnectionFactory.java	15 Apr 2001 17:31:40 -0000	1.2
--- DriverManagerConnectionFactory.java	13 Jun 2002 20:20:56 -0000
***************
*** 70,75 ****
--- 70,77 ----
   *
   * @author Rodney Waldhoff
   * @author Ignacio J. Ortega
+  * @author Jonathan Fuerth
+  * @author Dan Fraser
   *
   * @version $Id: DriverManagerConnectionFactory.java,v 1.2 2001/04/15 17:31:40 nacho Exp
$
   */
***************
*** 98,104 ****
                  return DriverManager.getConnection(_connectUri,_props);
              }
          } catch(SQLException e) {
!             throw new RuntimeException(e.toString());
          }
      }
  
--- 100,106 ----
                  return DriverManager.getConnection(_connectUri,_props);
              }
          } catch(SQLException e) {
!             throw new DBCPException(e, "Could not create database connection");
          }
      }
  
------- END DIFF

And the addition of this new class:

------- BEGIN DBCPException.java
package org.apache.commons.dbcp;

/*
 * (insert apache license here.. we disclaim everything about this file.)
 */

public class DBCPException extends RuntimeException {
	private Throwable _rootCause;
	
	public DBCPException(Throwable rootCause, String message) {
		super(message);
		_rootCause=rootCause;
	}

	public Throwable getRootCause() {
		return _rootCause;
	}
}
------- END DBCPException.java

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message