java - JDBC - 从 JAVA 调用 PLSQL 会产生 Java.sql.SQLException: ORA-06550
问题描述
我在从 Java 调用 PLSQL 时遇到了很大的麻烦。这是我的代码:
static final String PLSQL = "{call DBK_PDG_METADATI_CEDOLINO.dbp_main(?,?,?,?,?,?,?,?,?)}";
Connection conn = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
CallableStatement cs = conn.prepareCall(PLSQL);
for (Cedolino item : items) {
LOG.info("################# ELABORAZIONE CEDOLINO " + item.getTestata().getAnagrafica().getCodFiscaleAmministrato() + " #################");
cedolini.getCedolino().add(item);
setParametersForPlSql(cs, item);
try{
cs.execute();
}catch(SQLException e){
LOG.info(e.toString());
}
}
cs.close();
conn.close();
private void setParametersForPlSql(CallableStatement cs, Cedolino ced){
try {
cs.setInt("tipo_lancio", 1);
cs.setString("iscr", ced.getTestata().getTrattamento().getIscrizione().trim());
cs.setString("rts", ced.getTestata().getDpt().trim());
cs.setString("codfisc", ced.getTestata().getAnagrafica().getCodFiscaleAmministrato().trim());
cs.setString("lingua", this.lingua);
cs.setString("file_name", null);
cs.setString("dir_spec", null);
cs.setString("stato_elab", "S");
cs.setString("descr_elab", null);
} catch (SQLException e) {
e.printStackTrace();
}
}
这段代码很好用,除了cs.execute
,这给了我这个错误
java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'DBP_MAIN'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
我检查了一千次,参数和类型和数字完全匹配。数据库连接也很好,因为我先做了一些缓存并且它可以工作。
已经尝试删除DBK_PDG_METADATI_CEDOLINO
,但没有任何必要。你能帮我弄清楚吗?
解决方案
- 问题可能与可能不支持命名参数的 JDBC 驱动程序有关。
尝试先检查它,例如:
Connection myConn = . . . // connection to the RDBMS for Database
DatabaseMetaData dbmd = myConn.getMetaData();
if (dbmd.supportsNamedParameters() == true)
{
System.out.println("NAMED PARAMETERS FOR CALLABLE"
+ "STATEMENTS IS SUPPORTED");
}
如果不是 - 使用参数索引来设置而不是名称......
- 该存储过程中是否有任何 OUT 或 INOUT 参数?
如果是这样,您需要使用 注册这些参数registerOutParameter
并CallableStatement
为输出提供一个占位符。
推荐阅读
- python - 为什么我的字典排序函数不根据其值对其进行排序?
- python - 无法使用 pycharm 运行 kivy 文本输入,但它可以在终端中运行
- javascript - IE11 - 如何解决语法错误 mouseEvent?
- rust - 增加 Rust 中类型的特征要求
- ubuntu - Ubuntu 20.04(主机)上的 Vagrant 和旧版 ubuntu(来宾)
- php - PHP在switch case中翻译ENUM不起作用
- mysql - 如何从informix sql中的日期获取工作日名称?
- java - Flink 读取 Kafka,某些情况下消耗速度急剧下降
- php - Docker 挂载未列出文件
- makefile - 使用cmake构建时,以cmake结尾的文件有哪些