java - 存储函数 - 发送/接收 boolean 值 - BD

标签 java jdbc boolean jdbctemplate stored-functions

找到解决方案,见下文*

我试图通过 SimpleJdbcCall (使用 java + jpa)执行存储的函数,但我无法执行,它显示:

[Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: 
CallableStatementCallback; uncategorized SQLException for SQL [{? = call PK_BACKOFFICE.SET_PROFESSIONAL(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; 
SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type] with root cause
java.sql.SQLException: Invalid column type

这是我的代码:

    dataSource = this.getDataSource();
    SimpleJdbcCall caller = new SimpleJdbcCall(dataSource)
            .withCatalogName("pk_backoffice_api_ui")
            .withFunctionName("set_professional_main")
            .declareParameters(
                    new SqlOutParameter("result",OracleTypes.BOOLEAN),
                    new SqlParameter("i_id_institution",
                            OracleTypes.NUMERIC),
                    new SqlParameter("i_id_prof", OracleTypes.NUMERIC),
                    new SqlParameter("i_first_name", OracleTypes.VARCHAR),
                    new SqlParameter("i_nick_name", OracleTypes.VARCHAR),
                    new SqlParameter("i_gender", OracleTypes.VARCHAR),
                    new SqlParameter("i_id_category", OracleTypes.NUMERIC), 
                    new SqlParameter("i_id_lang", OracleTypes.NUMERIC),
                    new SqlParameter("i_flg_state", OracleTypes.VARCHAR),
                    new SqlParameter("i_commit_at_end", OracleTypes.BOOLEAN),
                    new SqlOutParameter("o_id_prof", OracleTypes.INTEGER),
                    new SqlOutParameter("o_error", OracleTypes.STRUCT, "T_ERROR_OUT")); 

    MapSqlParameterSource params = new MapSqlParameterSource()
            .addValue("i_id_institution", 2790)
            .addValue("i_id_prof", 7020000363724L)
            .addValue("i_first_name", "teste")
            .addValue("i_nick_name", "nicknameteste")
            .addValue("i_gender", "f").addValue("i_id_category", 20)
            .addValue("i_id_lang", 1).addValue("i_flg_state", "A")
            .addValue("i_commit_at_end", true);


    Integer res = caller.executeFunction(Integer.class, params);

    Map out = caller.execute(params);
    int idprof = (int) out.get("o_id_prof"); //getting out parameter?

    // para obter o erro - caso haja
    // (com.alert.core.plsql.types.TErrorOutType)__sJT_st.getORAData(35,com.alert.core.plsql.types.TErrorOutType.getORADataFactory());

    System.out.println(res);
    return res;
}

我意识到问题是向函数发送/接收 boolean 值..我还发现这是 jdbc 驱动程序的问题... BD 中没有编辑类型的选项,因此我确实需要找到一种发送/接收 boolean 值的方法。

..有什么建议吗?

最佳答案

解决方案是在函数调用中处理 boolean 值:

这意味着发送值而不是 ?/variable 并在调用中处理返回值(也是 boolean 值)*

@Resource(name = "myJdbcTemplate")
public JdbcTemplate simpleJdbc;

private Connection getConnection() throws SQLException{
    return simpleJdbc.getDataSource().getConnection();
}

    @Override
    public boolean setProfessionalBD(Professional professional,
    Category category, BigDecimal id_language, BigDecimal id_institution)
            throws SQLException {

    CallableStatement proc_strm = null;

    proc_strm = getConnection().prepareCall(
            "BEGIN ? := "
                    + "     CASE PK_BACKOFFICE.SET_PROFESSIONAL"
                    + "         (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,TRUE,?,?)"
                    + "     WHEN true " + "     THEN 1 " + "        ELSE 0 "
                    + "     END; " + "  END;");

    proc_strm.registerOutParameter(1, Types.INTEGER);
    proc_strm.setBigDecimal(2, id_language);
    proc_strm.setBigDecimal(3, id_institution);
    (...)
    proc_strm.execute();

关于java - 存储函数 - 发送/接收 boolean 值 - BD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23432192/

相关文章:

java - sonarLint:使这个匿名内部类成为 lambda

java - 我应该为 Android 布局使用 Java 还是 XML?

java - 如何在ubuntu中集成java和hive?

java - 复合类型Postgres的GetString?

java - 使用 boolean 值来识别/分离数组元素 (java)

java - 斯卡拉- Cassandra : cluster read fails with error "Can' t use this Cluster instance because it was previously closed"

java - 仅显示异常类型及其原因,而不是发生异常时的整个堆栈跟踪,而是显示在日志文件中

java - 玻璃鱼错误

c - 结构符号

python - 捕获表达式中值为 "or"的 None 值