使用ResultSet呈现数据时出错 [英] Error in rendering data using ResultSet
问题描述
使用ResultSet渲染数据时出现错误.我遇到此错误 java.sql.SQLException:ResultSet来自UPDATE.没有数据. 这是我的代码段
I'm having an error while rendering data using ResultSet. I'm having this error java.sql.SQLException: ResultSet is from UPDATE. No Data. Here's my code snippet
ArrayList<String> arrayList = new ArrayList<String>();
Session session = null;
Connection conn = null;
CallableStatement callableStatement = null;
try {
// test
BeanLocator beanLocator = PortletBeanLocatorUtil
.getBeanLocator("Mrcos-services-portlet");
BasicDataSource bds = (BasicDataSource) beanLocator
.locate("mrcosDataSourceTarget");
conn = bds.getConnection();
String sp = "{call TINChkSP(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
callableStatement = conn.prepareCall(sp);
callableStatement.setString(1, tin);
callableStatement.setString(2, branchCode);
callableStatement.setString(3, rdoCode);
callableStatement.registerOutParameter(4, Types.VARCHAR);
callableStatement.registerOutParameter(5, Types.VARCHAR);
callableStatement.registerOutParameter(6, Types.VARCHAR);
// all other callablestatement until all the 27 params are complete)
callableStatement.executeQuery();
ResultSet resultSet = callableStatement.executeQuery();
while (resultSet.next()) {
for (int i = 0; i <= 27; i++) {
arrayList.add(resultSet.getString(i));
}
}
我的ResultSet的输出为null,并提供给我 java.sql.SQLException:ResultSet来自UPDATE.没有数据.错误.请帮助谢谢.
The output of my ResultSet is null and gives me java.sql.SQLException: ResultSet is from UPDATE. No Data. error. Please help thanks.
编辑
我使用
callableStatement.getString(4);
callableStatement.getString(5);
callableStatement.getString(6);
EDIT
I checked the System.out of each parameters using callableStatement.getString(4);
callableStatement.getString(5);
callableStatement.getString(6);
,输出为:
42141
000
126
and the outputs are:
42141
000
126
推荐答案
在callableExecution.executeQuery()
之后,OUT参数的结果应该在callableStatement
变量中.
The result of your OUT parameters, after your callableExecution.executeQuery()
should be in the callableStatement
variable.
要在执行后获取它们,您必须按其类型进行获取,如下所示:
To get them after the execution you must get by its type, like this:
String valueForOutput4 = callableStatement.getString(4);
String valueForOutput5 = callableStatement.getString(5);
String valueForOutput6 = callableStatement.getString(6);
我假设您希望将所有27个固定参数传递到列表中的TINChkSP
数据库函数/过程.
我假设它们都是String
类型.
我还假定前三个参数不是OUT参数,但其他所有参数都是OUT或IN/OUT.
I assume that you want to have all the 27 fixed parameters passed to TINChkSP
database function/procedure in your List.
I assume that they are all of type String
.
I also assume that the first 3 parameters are not OUT parameters, but all of the others are OUT or IN/OUT.
这是一个可能的解决方案.
Here's a possible solution.
callableStatement.executeQuery();
// The first 3 elements are not OUT parameters (I guess)
List<String> values = Arrays.asList(tin, branchCode, rdoCode);
for (int i = 4; i <= 27; i++) {
values.add(callableStatement.getString(i));
}
System.out.println("The list: " + values.toString);
然后您可以删除对ResultSet
的使用,因为它会毫无用处.
You can then remove the use of ResultSet
, because it's gonna be useless.
希望有帮助.
这篇关于使用ResultSet呈现数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!