Skip to content

StatementUtil的getTypeOfNull函数,在某些情况下会空指针,需要规避 #3935

@yisiliang

Description

@yisiliang

某些数据库的getParameterMetaData 会返回 NULL,然后导致报错,也需要规避这种情况
原代码:

	public static int getTypeOfNull(PreparedStatement ps, int paramIndex) {
		int sqlType = Types.VARCHAR;

		final ParameterMetaData pmd;
		try {
			pmd = ps.getParameterMetaData();
			sqlType = pmd.getParameterType(paramIndex);
		} catch (SQLException ignore) {
			// ignore
			// log.warn("Null param of index [{}] type get failed, by: {}", paramIndex, e.getMessage());
		}

		return sqlType;
	}

需改成

	public static int getTypeOfNull(PreparedStatement ps, int paramIndex) {
		int sqlType = Types.VARCHAR;

		final ParameterMetaData pmd;
		try {
			pmd = ps.getParameterMetaData();
			if (pmd == null) {
			    return sqlType;
			}
			sqlType = pmd.getParameterType(paramIndex);
		} catch (SQLException ignore) {
			// ignore
			// log.warn("Null param of index [{}] type get failed, by: {}", paramIndex, e.getMessage());
		}

		return sqlType;
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions