{"record":{"id":"d1c122cdca7e45f3","repo":"pentaho/pentaho-kettle","slug":"error-connecting-to-database-using-class-classname","errorCode":null,"errorMessage":"Error connecting to database: (using class {classname})","messagePattern":"Error connecting to database: \\(using class (.+?)\\)","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":636,"sourceCode":"      String url = resolveUrl( partitionId );\n      String[] credentials = resolveCredentials( partitionId );\n      url = applyCredentialsToProperties( url, credentials[0], credentials[1], properties );\n\n      log.logDetailed( \"Acquiring JDBC connection for database [\" + databaseMeta.getName() + \"] using driver class [\" + classname + \"]...\" );\n      long startJdbc = System.currentTimeMillis();\n      if ( usingDynamicDriver ) {\n        connection = openConnectionViaDynamicDriver( jdbcDriverClass, url, properties );\n      } else {\n        connection = DriverManager.getConnection( url, properties );\n      }\n      log.logDetailed( \"JDBC connection acquired for database [\" + databaseMeta.getName() + \"] in \" + ( System.currentTimeMillis() - startJdbc ) + \" ms\" );\n    } catch ( SQLException sqlException ) {\n      closeDynamicClassLoader();\n      throw new KettleDatabaseException(\n        BaseMessages.getString( PKG, \"Database.Exception.ConnectionTestFailed\", toString() ), sqlException );\n    } catch ( Exception e ) {\n      closeDynamicClassLoader();\n      throw new KettleDatabaseException( \"Error connecting to database: (using class \" + classname + \")\", e );\n    }\n  }\n\n  private void loadStaticDriver( String classname, PluginInterface plugin ) throws KettleDatabaseException {\n    try {\n      synchronized ( java.sql.DriverManager.class ) {\n        ClassLoader classLoader = PluginRegistry.getInstance().getClassLoader( plugin );\n        Class<?> driverClass = classLoader.loadClass( classname );\n        // Only need DelegatingDriver for drivers not from our classloader\n        if ( driverClass.getClassLoader() != this.getClass().getClassLoader() ) {\n          registerDelegatingDriver( driverClass );\n        } else {\n          // Trigger static register block in driver class\n          Class.forName( classname );\n        }\n      }\n    } catch ( NoClassDefFoundError | ClassNotFoundException e ) {\n      throw new KettleDatabaseException( BaseMessages.getString( PKG,","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L618-L654","documentation":"connectUsingClass's generic catch (Exception) wraps any non-SQL failure during connection creation into KettleDatabaseException(\"Error connecting to database: (using class <classname>)\"). This covers everything other than SQLException — e.g. driver API mismatches, initialization errors inside the driver, or runtime exceptions from the database plugin class.","triggerScenarios":"A non-SQLException thrown while loading/initializing the driver class or obtaining the connection through the plugin's DatabaseInterface: ClassCastException, AbstractMethodError-like wrapper exceptions, or driver constructor/init failures.","commonSituations":"Driver version incompatible with the plugin interface (e.g. JDBC 4 driver with old code paths), corrupted driver jar, wrong driver class configured for the database type, security manager or OSGi classloading restrictions.","solutions":["Inspect the cause for the concrete non-SQL exception","Confirm the driver jar version is compatible with both the database server and the Kettle plugin","Verify the custom driver class name in DatabaseMeta is the correct one for that jar","Re-deploy the driver plugin to rule out a corrupted installation"],"exampleFix":"// before\ncustomDriverClass = \"com.mysql.jdbc.Driver\"; // legacy driver with newer connector\n\n// after\ncustomDriverClass = \"com.mysql.cj.jdbc.Driver\"; // matches Connector/J 8.x","handlingStrategy":"try-catch","validationCode":"try {\n  Class.forName( classname ); // verify driver loads before connectUsingClass\n} catch ( Throwable t ) {\n  log.error( \"Driver class \" + classname + \" cannot be initialized\", t );\n}","typeGuard":null,"tryCatchPattern":"try {\n  db.connect();\n} catch ( KettleDatabaseException e ) {\n  if ( e.getMessage().startsWith( \"Error connecting to database: (using class\" ) ) {\n    log.error( \"Non-SQL driver failure for \" + classname + \": \" + e.getCause(), e.getCause() );\n  }\n}","preventionTips":["Pin driver versions compatible with the server and the Kettle plugin","Avoid mixing multiple versions of the same driver on the classpath","Test driver loading in isolation when introducing new database types"],"tags":["jdbc","driver","class-loading"],"backgroundTag":"driver-initialization-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}