尝试使用Spring JdbcTemplate从Java访问AS400 / DB2存储过程,
XmlBeanFactory beanFactory2 = new XmlBeanFactory(new ClassPathResource(
"datasource_as400.xml"));
DataSource ds2 = (DataSource) beanFactory2.getBean("dataSource");
jdbc2 = new JdbcTemplate(ds2);
jdbc2.update("{CALL TESTONE(?)}", new Object[] { new String("JOHN") });
我收到以下错误
[DEBUG,SQLErrorCodeSQLExceptionTranslator] Translating SQLException with SQL state '42704', error code '-204', message [[SQL0204] TESTONE in type *N not found.]; SQL was [{CALL TESTONE(?)}] for task [PreparedStatementCallback]
[FATAL,MainBatch] processDonations(): org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [{CALL TESTONE(?)}]; nested exception is java.sql.SQLException: [SQL0204] TESTONE in type *N not found.
最佳答案
根据iSeries Info Center,SQLCODE -204
表示An undefined object or constraint name was detected.
您可能必须指定函数所在的架构。(即CALL YOUR_SCHEMA.TESTONE(?)
)。
如果它在另一个程序中工作(或当您手动查询时),则您的架构路径可能会设置为不同。您可以通过执行SELECT CURRENT_SCHEMA FROM SYSIBM.SYSDUMMY1
来检查(我不确定SYSIBM.SYSDUMMY1
是否在iSeries上,或者虚拟表是否存在其他名称...我习惯于z / OS或Linux / Unix / Windows DB2 )。