我正在尝试读取ref游标,它只返回一列,一个字符串数据列表。
我该怎么做java?我是否必须遍历每个结果集,或者是否有任何方法可以让我可以一次性获取整个列。我从程序中得到5个参考光标。
rs1= (ResultSet) callableStatement.getObject(1);
rs2= (ResultSet) callableStatement.getObject(2);
rs3= (ResultSet) callableStatement.getObject(3);
while(rs1.next()){
list1.add(rs1.getString(1));
}
while(rs2.next()){
list2.add(rs2.getString(1));
}
while(rs3.next()){
list3.add(rs3.getString(1));
}
答案 0 :(得分:0)
这可能会有所帮助:
ResultSet result=null ;
PreparedStatement pstmt = null;
ArrayList yourlist = new ArrayList();
try
{
String queryString = "select yourfield from ....";
result = pstmt.executeQuery();
while(result.next())
{
yourlist.add(result.getInt("yourfield")); //if you are returning varchar so use getString
}
}
catch (SQLException e){
System.out.println("Exception: " + e.toString() );
}
finally
{
if(result!=null)
result.close();
if(pstmt!=null)
pstmt.close();
}