baomidou/mybatis-plus · error · RuntimeException
读取[%s]字段出错!
Error message
读取[%s]字段出错!
What it means
ResultSetWrapper.getStringResult wraps the SQLException thrown by ResultSet.getString(columnLabel) for a single metadata column (table name, remarks, key name, etc.). It means the configured IDbQuery asked the ResultSet for a column label the executed metadata query did not produce.
Source
Thrown at mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DbQueryDecorator.java:243
private final IDbQuery dbQuery;
@Getter
private final ResultSet resultSet;
private final DbType dbType;
ResultSetWrapper(ResultSet resultSet, IDbQuery dbQuery, DbType dbType) {
this.resultSet = resultSet;
this.dbQuery = dbQuery;
this.dbType = dbType;
}
public String getStringResult(String columnLabel) {
try {
return resultSet.getString(columnLabel);
} catch (SQLException sqlException) {
throw new RuntimeException(String.format("读取[%s]字段出错!", columnLabel), sqlException);
}
}
/**
* @return 获取字段注释
*/
public String getFiledComment() {
return getComment(dbQuery.fieldComment());
}
/**
* 获取格式化注释
*
* @param columnLabel 字段列
* @return 注释
*/
private String getComment(String columnLabel) {
return StringUtils.isNotBlank(columnLabel) ? formatComment(getStringResult(columnLabel)) : StringPool.EMPTY;View on GitHub (pinned to bf67d90747)
Solutions
- Read the wrapped SQLException to see the missing column label and the SQL that ran; the mismatch is usually obvious.
- Do not force dbQuery manually — pass the correct JDBC URL and let DataSourceConfig infer the DbType, so the matching adapter is used.
- If a custom IDbQuery is used, verify every column label in tableName()/tableComment()/fieldNames() is selected by your tablesSql()/columnsSql().
- Upgrade the JDBC driver to one whose metadata column labels match what the bundled adapter expects.
Example fix
// before new DataSourceConfig.Builder(url, user, pass).dbQuery(new MySqlQuery()); // url is postgres // after new DataSourceConfig.Builder(url, user, pass); // DbType auto-detected from URL -> PostgreSqlQuery
Defensive patterns
Strategy: validation
Validate before calling
// Before generating: verify DbType inferred from URL matches the adapter you intend DataSourceConfig ds = new DataSourceConfig.Builder(url, user, pass).build(); // ensure you did NOT force a mismatched dbQuery; rely on auto-detection: // ds.getDbQuery() must be an instance of the adapter for your real database
Try / catch
try {
generator.generate();
} catch (RuntimeException e) {
Throwable root = e;
while (root.getCause() != null) root = root.getCause();
if (root instanceof SQLException) log.error("metadata column mismatch: {}", root.getMessage());
} Prevention
- Never hardcode dbQuery for a different database than the JDBC URL.
- Smoke-test the generator against a scratch schema whenever the DB or driver is upgraded.
- For custom IDbQuery, keep tablesSql/columnsSql and the field-name accessors in one reviewed file.
When it happens
Trigger: Any DbQueryDecorator metadata read (tableName(), tableComment(), fieldName()...) where the driver fails to resolve columnLabel — mismatched DbType (e.g. DbType set to MYSQL against a PostgreSQL URL), custom IDbQuery tablesSql/columnsSql not matching fieldNames(), or driver metadata column renames.
Common situations: Setting dbQuery/DbType explicitly to a wrong database type so the adapter's SQL runs but returns different column names; using a custom IDbQuery copied from another database's adapter without adjusting the column labels; older JDBC drivers returning lowercase/uppercase labels.
Related errors
- 获取自定义字段错误:
- `url` cannot be empty
- %s 的名称转换结果为空,请检查是否配置问题
- `include` and `exclude` configurations are mutually exclusiv
- `likeTable` and `notLikeTable` configurations are mutually e
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/5dabde18ce63b8a2.
Report an issue: GitHub.