commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp BasicDataSource.java
Date Sun, 21 Sep 2003 13:42:53 GMT
dirkv       2003/09/21 06:42:53

  Modified:    dbcp/src/java/org/apache/commons/dbcp BasicDataSource.java
  Log:
  Bugzilla Bug 23304:  NullpointerException when no driverClassName is specified
  When you don't configure a driver you will get this exception:
  java.sql.SQLException: No suitable driver
  
  Revision  Changes    Path
  1.29      +21 -13    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java
  
  Index: BasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- BasicDataSource.java	20 Sep 2003 17:31:05 -0000	1.28
  +++ BasicDataSource.java	21 Sep 2003 13:42:53 -0000	1.29
  @@ -161,7 +161,12 @@
       }
   
       public void setDriverClassName(String driverClassName) {
  -        this.driverClassName = driverClassName;
  +        if ((driverClassName != null) && (driverClassName.trim().length() >
0)) {
  +            this.driverClassName = driverClassName;
  +        }
  +        else {
  +            this.driverClassName = null;
  +        }
       }
   
   
  @@ -720,14 +725,16 @@
           }
   
           // Load the JDBC driver class
  -        try {
  -            Class.forName(driverClassName);
  -        } catch (Throwable t) {
  -            String message = "Cannot load JDBC driver class '" +
  -                driverClassName + "'";
  -            logWriter.println(message);
  -            t.printStackTrace(logWriter);
  -            throw new SQLNestedException(message, t);
  +        if (driverClassName != null) {
  +            try {
  +                Class.forName(driverClassName);
  +            } catch (Throwable t) {
  +                String message = "Cannot load JDBC driver class '" +
  +                    driverClassName + "'";
  +                logWriter.println(message);
  +                t.printStackTrace(logWriter);
  +                throw new SQLNestedException(message, t);
  +            }
           }
   
           // Create a JDBC driver instance
  @@ -736,7 +743,8 @@
               driver = DriverManager.getDriver(url);
           } catch (Throwable t) {
               String message = "Cannot create JDBC driver of class '" +
  -                driverClassName + "' for connect URL '" + url + "'";
  +                (driverClassName != null ? driverClassName : "") + 
  +                "' for connect URL '" + url + "'";
               logWriter.println(message);
               t.printStackTrace(logWriter);
               throw new SQLNestedException(message, t);
  
  
  

Mime
View raw message