我在从 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 参数?
如果是这样,您需要使用 CallableStatement
的 registerOutParameter
注册这些参数,并为输出提供占位符。
关于java - JDBC - 从 JAVA 调用 PLSQL 会出现 Java.sql.SQLException : ORA-06550,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53013246/