2

尝试插入行时出现异常

java.sql.SQLException: Parameter metadata not available for the given statement
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.MysqlParameterMetadata.checkAvailable(MysqlParameterMetadata.java:70)
    at com.mysql.jdbc.MysqlParameterMetadata.getParameterType(MysqlParameterMetadata.java:119)
    at org.springframework.jdbc.core.StatementCreatorUtils.setNull(StatementCreatorUtils.java:231)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:213)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:144)
    at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.doSetValue(ArgumentPreparedStatementSetter.java:65)
    at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.setValues(ArgumentPreparedStatementSetter.java:46)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:822)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:818)

我插入成功的地方,但是在看到控制台后,我发现在插入过程中抛出了异常。

尽管此异常不会停止我的流程,但当实际插入出现错误时会导致潜在问题,例如,我在表中有唯一列,当我尝试使用重复的列值时,我没有得到 MySQLIntegrityConstraintViolationException,我需要处理这个(事情。

编辑:-

public int addUserAcc(UserDO userDO)
        throws UserDataException {
    JdbcTemplate jd = this.getJdbctemplate();
    try {
        Long userId= jd.queryForObject(USER_KEY,
                Long.class);
        jd.update(ADD_USERACC, new Object[] { userId,
                userDO.getFirstName(), userDO.getLastName(),
                userDO.getMobile(), userDO.getEmail(),
                userDO.deleteFlag() });
    } catch (DataAccessException dExp) {
        throw new UserDataException(
                "error creating user ", dExp);

    }
    return 0;
}

感谢您的回答。

4

1 回答 1

0

我遇到了同样的异常,这是因为类型没有被指定为第三个参数。

于 2017-11-01T21:23:41.017 回答