【发布时间】:2020-02-16 07:55:28
【问题描述】:
我正在从 Oracle DB 迁移到 Postgres。我在 oracle 中使用存储过程,并使用 jdbc 模板在我的 Spring Boot 代码中访问它们。使用 postgres 存储过程运行代码时出现错误。这是我的代码的 sn-p:
@Repository
public class DatabaseImpl implements RegistrationDao {
@Autowired
DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private SimpleJdbcCall spStoreTempData;
@PostConstruct
private void postConstruct() throws SQLException {
jdbcTemplate = new JdbcTemplate(dataSource);
spStoreTempData = new SimpleJdbcCall(jdbcTemplate).withProcedureName("stmt_temp_store").withSchemaName("my_schema");
}
@Override
public Map<String, Object> storeTempData(String v_user_type, String v_refid, String v_phone, String v_scode, String v_id_number, String v_email,
String v_tnc, String v_channel, String v_temp_uuid, String v_totp, String v_totp_expperiod, String v_svc_type, String v_reason, String v_max_retries) {
SqlParameterSource in = new MapSqlParameterSource()
.addValue("v_user_type", v_user_type)
.addValue("v_refid", v_refid)
.addValue("v_phone", v_phone)
.addValue("v_scode", v_scode)
.addValue("v_id_number", v_id_number)
.addValue("v_email", v_email)
.addValue("v_tnc", v_tnc)
.addValue("v_channel", v_channel)
.addValue("v_temp_uuid", v_temp_uuid)
.addValue("v_totp", v_totp)
.addValue("v_totp_expperiod", v_totp_expperiod)
.addValue("v_svc_type", v_svc_type)
.addValue("v_reason", v_reason)
.addValue("v_max_retries", v_max_retries)
.addValue("v_code", "")
.addValue("v_msg", "");
Map<String, Object> result = null;
try {
result = spStoreTempData.execute(in);
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
return result;
}
}
执行此代码时,我收到以下错误:
CallableStatementCallback; bad SQL grammar [{? = call my_schema.stmt_temp_store(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; nested exception is org.postgresql.util.PSQLException: ERROR: my_schema.stmt_temp_store(numeric, character varying, numeric, numeric, character varying, character varying, character varying, character varying, character varying, numeric, character varying, numeric, character varying, numeric, character varying, character varying) is a procedure
Hint: To call a procedure, use CALL.
Position: 15
我做错了什么? Here is a link 使用 oracle db 时代码的工作原理
【问题讨论】:
-
可能的解决方法:编写一个函数,
CALLs 存储过程并返回一些东西。或者只是将过程设为函数(它们在 PostgreSQL 中是相同的,但过程不能返回值,只能出现在CALL语句中,而不是SELECT中)。
标签: postgresql spring-boot stored-procedures jdbc