Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-96

DbUtils#loadDriver(ClassLoader,String) makes DriverManager throwing "No suitable driver found for jdbc" if ClassLoader is not the System's one

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6
    • None
    • jdk 1.6

    Description

      By this way(use Dbutil get connect),it will say: No suitable driver found for jdbc:mysql://127.0.0.1:3306/xxx

      urls = new URL[1];
      urls[0] = new File("d:\mysql_connector_5.1.15_bin.jar").toURL();
      URLClassLoader urlClassLoader= new URLClassLoader(urls, ClassLoader.getSystemClassLoader())		
      DbUtils.loadDriver(urlClassLoader, driver);
      
      Properties conProps = new Properties(); 
      conProps.put("user", user); 
      conProps.put("password", pwd); 
      conProps.put("defaultRowPrefetch", "20");
      
      scanedConnection = DriverManager.getConnection(url, conProps);
      

      but by this way (use jdbc's api get connect),it's ok

      try {
          URL jdbcDriverURL = new File("d:\\mysql_connector_5.1.15_bin.jar").toURL();
          URL[] urls = new URL[1];
          urls[0] = jdbcDriverURL;
          URLClassLoader urlclassLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
          try {
              java.sql.Driver driverd = (java.sql.Driver) urlclassLoader.loadClass(driver).newInstance();
              System.out.println(driverd.toString());
              Properties props = new Properties();
              props.setProperty("user", theUser);
              props.setProperty("password", thePw);
              try {
                  c = driverd.connect(dbUrl, props);
              } catch (SQLException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          } catch (InstantiationException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      } catch (MalformedURLException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
      

      is this a bug or my useing falut?

      Attachments

        1. DBUTILS-96_v2.patch
          3 kB
          Simone Tripodi
        2. DBUTILS-96_v3.patch
          4 kB
          Simone Tripodi
        3. DBUTILS-96.patch
          3 kB
          Simone Tripodi
        4. dbutils-96.tar.gz
          737 kB
          Simone Tripodi
        5. dynamicloadjar.zip
          782 kB
          yuyf
        6. mysql.properties
          0.1 kB
          yuyf

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            simone.tripodi Simone Tripodi
            yyflyons yuyf
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment