我有一个SQL查询:
DECLARE @output varchar(100) exec map.GetGenreStatusName 'Genre', '2018-03-16', @output OUTPUT select @output;
它返回smth,如:
<anonymous>
Completed
我需要从java代码中获取它。我的变体是:
final String statusCheck = "DECLARE @output varchar(100) exec map.GetGenreProtocolStatusName ?, ?, ? OUTPUT select @output;";
List<String> chekList = new ArrayList<>();
try (CallableStatement statement = connection.prepareCall(statusCheck)) {
statement.setString(1, packageName);
statement.setDate(2, date);
statement.registerOutParameter("output", 12);
statement.execute();
ResultSet checkStatusResult = (ResultSet) statement.getObject(0);
chekList.add(checkStatusResult.getString(0));
}
如何从select到我的列表中将此字符串“Completed”?我用“?”尝试了不同的变种设置和注册输入/输出参数,我尝试像查询一样执行它,但没有。
答案 0 :(得分:0)
已将字符串更改为:
final String statusCheck = "exec map.GetGenreProtocolStatusName ?, ?, ?;";
代码:
final Connection connection = DriverManager.getConnection(dataSourceUrl,dbProperties);
List<TvScheduleInterval> scheduleIntervals = new ArrayList<>();
List<String> checkList = new ArrayList<>();
try (CallableStatement statement = connection.prepareCall(statusCheck)) {
statement.setString(1, packageName);
statement.setDate(2, date);
statement.registerOutParameter(3,12);
statement.execute();
checkList.add(statement.getString(3));
}
立即工作。