我们有一个SQLJ文件,我们指定了一个迭代器来从表中获取多个记录。目前,我们尝试通过一次从总共300条记录中提取50条记录,将300条记录从中间表上传到实际表中。
我们面临的问题是,每次获取都会创建50个迭代器,其中1个游标是DICTIONARY LOOKUP CURSOR CACHED,49个是OPEN-RECURSIVE。在我们循环遍历迭代器后,我们在finally块中进行了一次close调用,但是这会关闭一个游标,我们剩下48个OPEN-RECURSIVE游标和1个DICTIONARY LOOKUP CURSOR CACHED。我想知道是否有任何具体方法可以关闭所有这些。我试图在网上查看,但在这种情况下我们并没有真正想到这个问题。
#sql public static iterator UploadDetailsList(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
#sql public static iterator UploadDetailsListAnother(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
public List<UploadDto> getRecords(UploadDto newDto,int fromRowNo){
//fromRowNo is sent as 0
int maxResults=50;
int toRowNum= fromRowNo + maxResults;
UploadDetailsList uploadDetailsList=null;
UploadDetailsListAnother uploadDetailsListAnother=null;
try{
#sql uploadDetailsList = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
while(uploadDetailsList.next()){
//populate details to Dto object
try{
#sql uploadDetailsListAnother = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
while(uploadDetailsListAnother.next()){
//populate details to Dto object
}
}
catch(Exception e){
//print error
}
}
}
catch(Exception e){
//print error
}
finally{
try{
dbg("Inside finally in List<UploadDto> getRecords(UploadDto newDto,int fromRowNo)");
if(uploadDetailsList != null){
dbg("Closing uploadDetailsList");
uploadDetailsList.close();
}
if(uploadDetailsListAnother != null){
dbg("Closing uploadDetailsListAnother");
uploadDetailsListAnother.close();
}
}
catch(Exception e){
//print error
}
}
}
有人可以让我知道我哪里出错了,还是有什么我可能会失踪的?
答案 0 :(得分:0)
发现了我犯的最愚蠢的错误。第一个while循环中的第二个迭代器应该已经关闭然后在try迭代器的try catch之后有一个finally块。这对我有用。将问题留在这里以防其他人犯同样的错误。 这是代码
#sql public static iterator UploadDetailsList(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
#sql public static iterator UploadDetailsListAnother(BigDecimal ID, String FUNCTION_ID,String TABLE_NAME)
public List<UploadDto> getRecords(UploadDto newDto,int fromRowNo){
//fromRowNo is sent as 0
int maxResults=50;
int toRowNum= fromRowNo + maxResults;
UploadDetailsList uploadDetailsList=null;
UploadDetailsListAnother uploadDetailsListAnother=null;
try{
#sql uploadDetailsList = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
while(uploadDetailsList.next()){
//populate details to Dto object
try{
#sql uploadDetailsListAnother = {SELECT ID,FUNCTION_ID,TABLE_NAME FROM UPLOAD_TABLE WHERE STATUS= 'U' AND ROWNUM BETWEEN :fromRowNo AND :toRowNum};
while(uploadDetailsListAnother.next()){
//populate details to Dto object
}
}
catch(Exception e){
//print error
}
//moved the finally here with closing of the inner iterator
finally{
try{
if(uploadDetailsListAnother != null){
dbg("Closing uploadDetailsListAnother");
uploadDetailsListAnother.close();
}
}
catch(Exception e){
//print error
}
}
}
}
catch(Exception e){
//print error
}
finally{
try{
dbg("Inside finally in List<UploadDto> getRecords(UploadDto newDto,int fromRowNo)");
if(uploadDetailsList != null){
dbg("Closing uploadDetailsList");
uploadDetailsList.close();
}
}
catch(Exception e){
//print error
}
}
}