{"record":{"id":"36987ef4efa2a59f","repo":"MyCATApache/Mycat-Server","slug":"er-parse-error-36987e","errorCode":"ER_PARSE_ERROR","errorMessage":"msg == null ? e.getClass().getSimpleName() : msg","messagePattern":"msg == null \\? e\\.getClass\\(\\)\\.getSimpleName\\(\\) : msg","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java","lineNumber":363,"sourceCode":"\t\t\tpublic void doExecute(List param) {\n\t\t\t\tsc.getSession2().setMiddlerResultHandler(null);\n\t\t\t\tString sqls = null;\n\t\t\t\t// 路由计算\n\t\t\t\tRouteResultset rrs = null;\n\t\t\t\ttry {\n\n\t\t\t\t\tsqls = buildSql(statement,sqlselect,param);\n\t\t\t\t\trrs = MycatServer\n\t\t\t\t\t\t\t.getInstance()\n\t\t\t\t\t\t\t.getRouterservice()\n\t\t\t\t\t\t\t.route(MycatServer.getInstance().getConfig().getSystem(),\n\t\t\t\t\t\t\t\t\tschema, sqlType,sqls.toLowerCase(), charset,sc );\n\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tStringBuilder s = new StringBuilder();\n\t\t\t\t\tLOGGER.warn(s.append(this).append(sqls).toString() + \" err:\" + e.toString(),e);\n\t\t\t\t\tString msg = e.getMessage();\n\t\t\t\t\tsc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tNonBlockingSession noBlockSession =  new NonBlockingSession(sc.getSession2().getSource());\n\t\t\t\tnoBlockSession.setMiddlerResultHandler(null);\n\t\t\t\t//session的预编译标示传递\n\t\t\t\tnoBlockSession.setPrepared(sc.getSession2().isPrepared());\n\t\t\t\tif (rrs != null) {\n\t\t\t\t\tnoBlockSession.setCanClose(false);\n\t\t\t\t\tnoBlockSession.execute(rrs, ServerParse.SELECT);\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tsc.getSession2().setMiddlerResultHandler(middlerResultHandler);\n\t\tsc.getSession2().setCanClose(false);\n\n\t\t// 路由计算\n\t\tRouteResultset rrs = null;\n\t\ttry {","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java#L345-L381","documentation":"DruidMycatRouteStrategy.doExecute routes a multi-statement SQL through the Druid parser/router. If routing throws (parse error, unknown table, config problem), the exception is logged and its message — or the exception class simple name when the message is null — is sent to the client as an ER_PARSE_ERROR MySQL error. This is the generic 'your statement could not be routed' failure of the Druid-based strategy.","triggerScenarios":"Executing SQL that Druid's parser cannot handle (unsupported syntax, MySQL 8 features, comments/hints Druid rejects), or routing throwing due to missing schema/table/primaryKey configuration; also e.getMessage() returning null (e.g. NPE) which degrades to the exception class name in the client error.","commonSituations":"Statements with newer MySQL syntax unsupported by the bundled Druid version, queries against tables absent from schema.xml, NPEs during routing producing 'NullPointerException' as the client-visible message, multi-statement strings where one clause fails.","solutions":["Look at the server log line ending with 'err:' to see the full stack trace of the real routing exception.","Fix the SQL syntax to something Druid supports, or upgrade the Druid dependency for newer MySQL syntax support.","Ensure the referenced tables/schemas/dataNodes exist in schema.xml with correct primaryKey settings.","If the client message is just a class name (message was null), reproduce in tests to capture the actual NPE cause and fix the config/route logic."],"exampleFix":"// before: SQL Druid cannot parse (MySQL 8 CTE variant)\nWITH cte AS (SELECT ...) SELECT * FROM cte;\n// after: rewrite with a subquery or upgrade Druid\nSELECT * FROM (SELECT ...) AS cte;","handlingStrategy":"try-catch","validationCode":"// check the statement targets configured tables before routing\nfor (String tbl : extractTables(sql)) {\n  if (!mycatSchema.tablesContain(tbl)) throw new IllegalStateException(\"table not configured: \" + tbl);\n}","typeGuard":null,"tryCatchPattern":"try {\n  stmt.execute(sql);\n} catch (SQLException e) {\n  if (e.getErrorCode() == 1064 /* ER_PARSE_ERROR */) {\n    logger.error(\"route/parse failed, check server log 'err:' line; sql={}\", sql);\n  }\n}","preventionTips":["Test new SQL syntax against the bundled Druid version before release.","Keep schema.xml table definitions in sync with the database.","Upgrade Druid when adopting newer MySQL syntax.","Read the full server-side stack trace — the client message may be just the exception class name."],"tags":["routing","sql-parsing","druid","parse-error"],"backgroundTag":"sql-query-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}