gpt4 book ai didi

postgresql - 使用 jdbc 模板从 spring boot 调用 postgres 存储过程

转载 作者:行者123 更新时间:2023-12-05 07:18:12 24 4
gpt4 key购买 nike

<分区>

我正在从 Oracle 数据库迁移到 Postgres。我在 oracle 中使用存储过程并使用 jdbc 模板在我的 spring 引导代码中访问它们。使用 postgres 存储过程运行我的代码时出现错误。这是我的代码片段:

@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 数据库时代码是如何工作的

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com