{"record":{"id":"6210437cb30205e8","repo":"pentaho/pentaho-kettle","slug":"problem-encountered-determining-query-fields","errorCode":null,"errorMessage":"Problem encountered determining query fields: ","messagePattern":"Problem encountered determining query fields: ","errorType":"exception","errorClass":"InvocationTargetException","httpStatus":null,"severity":"error","filePath":"ui/src/main/java/org/pentaho/di/ui/core/database/dialog/GetQueryFieldsProgressDialog.java","lineNumber":68,"sourceCode":"   */\n  public GetQueryFieldsProgressDialog( Shell shell, DatabaseMeta dbInfo, String sql ) {\n    this.shell = shell;\n    this.dbMeta = dbInfo;\n    this.sql = sql;\n  }\n\n  public RowMetaInterface open() {\n    IRunnableWithProgress op = new IRunnableWithProgress() {\n      public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {\n        db = new Database( Spoon.loggingObject, dbMeta );\n        try {\n          db.connect();\n          result = db.getQueryFields( sql, false );\n          if ( monitor.isCanceled() ) {\n            throw new InvocationTargetException( new Exception( \"This operation was cancelled!\" ) );\n          }\n        } catch ( Exception e ) {\n          throw new InvocationTargetException( e, \"Problem encountered determining query fields: \" + e.toString() );\n        } finally {\n          db.close();\n        }\n      }\n    };\n\n    try {\n      final ProgressMonitorDialog pmd = new ProgressMonitorDialog( shell );\n\n      // Run something in the background to cancel active database queries, forecably if needed!\n      Runnable run = new Runnable() {\n        public void run() {\n          IProgressMonitor monitor = pmd.getProgressMonitor();\n          while ( pmd.getShell() == null || ( !pmd.getShell().isDisposed() && !monitor.isCanceled() ) ) {\n            try {\n              Thread.sleep( 250 );\n            } catch ( InterruptedException e ) {\n              // Ignore","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/ui/src/main/java/org/pentaho/di/ui/core/database/dialog/GetQueryFieldsProgressDialog.java#L50-L86","documentation":"In GetQueryFieldsProgressDialog.run, any exception thrown while connecting or while db.getQueryFields(sql, false) determines the result-row fields is rethrown as an InvocationTargetException with the message 'Problem encountered determining query fields: ' plus the underlying exception's toString().","triggerScenarios":"Invoking the dialog with SQL that the database rejects — syntax errors, unknown tables/columns, connect failure, insufficient privileges — so getQueryFields throws inside the runnable.","commonSituations":"Typing an invalid SQL statement in Spoon's SQL editor and clicking 'Get fields'; running SQL against a database whose connection has timed out; SQL using vendor-specific syntax the driver cannot prepare.","solutions":["Read the cause (e.getMessage() of the InvocationTargetException) for the real SQL/database error and fix the statement.","Validate the SQL by executing it directly in the database's client before using 'Get fields'.","Test/refresh the database connection; reconnect if the session was dropped.","Check that the user has permissions to run the statement and read the referenced tables."],"exampleFix":"// before\nresult = db.getQueryFields( sql, false );\n// after\nif ( dbMeta.testConnection( loggingObject ).length == 0 ) {\n  result = db.getQueryFields( sql, false );\n} else {\n  throw new KettleException( \"Database connection invalid; cannot determine query fields\" );\n}","handlingStrategy":"try-catch","validationCode":"// basic SQL sanity before asking for fields\nif ( sql == null || sql.trim().isEmpty() ) throw new IllegalArgumentException( \"SQL statement is empty\" );","typeGuard":null,"tryCatchPattern":"try {\n  fields = new GetQueryFieldsProgressDialog( shell, loggingObject, dbMeta, sql ).open();\n} catch ( InvocationTargetException e ) {\n  logError( \"Problem determining query fields: \" + e.getCause(), e.getCause() );\n}","preventionTips":["Validate SQL syntax in the database's own client before 'Get fields'.","Ensure the connection is alive (testConnection) first.","Check user permissions on all referenced tables."],"tags":["jdbc","sql","database","query-fields"],"backgroundTag":"sql-query-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"}