gpt4 book ai didi

java - Spring:带动态参数的SimpleJdbcCall

转载 作者:行者123 更新时间:2023-11-30 10:30:35 24 4
gpt4 key购买 nike

我有一个使用 SimpleJdbcCall 的道调用 postgres 函数:

public final class AuthDAO extends UntypedActor {

private final ActorRef manager;

private final JdbcTemplate jdbcTemplate;

private final SimpleJdbcCall jdbcCall;

public AuthDAO(ActorRef manager) {
this.manager = manager;
jdbcTemplate = DBConfig.jdbcTemplate();
jdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("auth")
.withCatalogName("public")
.withoutProcedureColumnMetaDataAccess();
}

public static Props create(ActorRef manager) {
return Props.create(AuthDAO.class, manager);
}

@Override
public void onReceive(Object o) throws Throwable {
if (o instanceof DBMessage) {

DBMessage message = (DBMessage) o;
jdbcCall.declareParameters(new SqlParameter("login", Types.VARCHAR));
Map<String, Object> response = jdbcCall
.withProcedureName(message.getProcedure())
.execute(message.getParams());

System.out.println(response.toString());
}
}
}

但现在我必须通过调用 jdbcCall.declareParameters() 显式声明函数的参数,否则代码将无法运行。

那么有没有办法动态检测函数参数的名称和类型,并使用这样的 dao 调用仅传递函数名称的不同函数?

最佳答案

figured it out .

Explicit declarations are necessary if the database you use is not a Spring-supported database. Currently Spring supports metadata lookup of stored procedure calls for the following databases: Apache Derby, DB2, MySQL, Microsoft SQL Server, Oracle, and Sybase. We also support metadata lookup of stored functions for MySQL, Microsoft SQL Server, and Oracle.

而且,我的天啊,我用的是 Postgres。

关于java - Spring:带动态参数的SimpleJdbcCall,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43656566/

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