• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Resultset Close Error....

 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I m using two resultset for two while and creating two directory in one another, then i m getting first resultset rs_group close error where directory is created successfully but first resulset is not processed where still not close any resultset, anybody can suggest why first resulset get close,my code structure look like this-
Any helping solution appreciated.


try{
//System.out.println("Getting data -------->");
sql = "SELECT col1, col2 FROM COMPANY ";
rs_group = DBConnector.stmt.executeQuery(sql);
while(rs_group.next()) //Outer loop
{
String company_group = rs_group.getString("col1");
String company_sub_group = rs_group.getString("col2");
group = new File(path + "\\" + company_group.trim());
if(!group.isDirectory())
{
group.mkdir();
System.out.println("Folder Created"+company_group);
}
sql2 = "select col3,col4 from COMPANY";
rsgroupdata = DBConnector.stmt.executeQuery(sql2);
//creating excel file
if(group.isDirectory())
{
subgroup = new File(path + "\\" + company_group.trim() + "\\" + company_sub_group.trim());
subgroup.mkdir();
}
String fname = "data";
String filecreate = path + "\\" + company_group.trim() + "\\" + company_sub_group.trim() + "\\"+fname+"_"+date+".xls";
try{
fileOut = new FileOutputStream(filecreate);
}catch(Exception e) {System.out.println("File Error : "+e);}
while(rsgroupdata.next()) //inner loop {
System.out.println("Inside while loop");
++rowNum;
//System.out.println(rowNum);
String col1 = rsgroupdata.getString(1);
String col2 = rsgroupdata.getString(2);
HSSFRow row1 = sheet.createRow(rowNum);

row1.createCell((short)0).setCellValue(col1);
row1.createCell((short)1).setCellValue(col2);
} // end of rsgroupdata loop

try{
wb.write(fileOut);
fileOut.close();
}catch(Exception e) {System.out.println("File close/write Error : "+e);}
System.out.println("File Created");
} // end of rs_group record set
}catch(SQLException e) {System.out.println("Other Error :" +e);}


Thanx
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin,
It looks like you are trying to have two resultsets open from the same statement object at the same time. Opening the second resultset automatically closes the first.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More specifically, each Connection can have only one open ResultSet. You need to open two Connections to use two ResultSets simultaneously.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Harkness:
More specifically, each Connection can have only one open ResultSet. You need to open two Connections to use two ResultSets simultaneously.


When i need two result sets i w'd normally use two Statement objects & two ResultSet objects for the reason mentioned above by Jeanne. But i use only one connection object it worked out well.. Am i going wrong any where, guide me please
[ February 20, 2005: Message edited by: Srinivasa Raghavan ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Harkness:

each Connection can have only one open ResultSet.

You need to open two Connections to use two ResultSets simultaneously.



David can you provide details.
As per my knowledge we can have many resultset associated with one connection.
however If connection is made closed then all resultset will not be available.

thanks..
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used JDBC more than minimally in the past several years, so I may be mistaken on this, but I thought that only one ResultSet could be open for a single Connection. Certainly transactions work this way (one active per Connection), but logically I see no reason that would demand one ResultSet per Connection.

You definitely cannot access a ResultSet after its Connection has been closed.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin,

As Jeanne Said, your problem seems to related with statement.
it seems you are using same statement for both resultset.

thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDoc for Statement:
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.


The implicit close the JavaDoc refers to is closing the first resultset.
 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

One connection can have multiple open resultsets. The issue is that in case you are using nested resultset loops like the foll code snippet :

while(rs.next())
{
// Do something //
while(rs1.next())
{
// Do something //
}
}

Then,

Resultsets rs and rs1 should have been executed using different statement objects. The connection can be same or different.

Regards,
Prabhu Chandrasekaran.
 
Hareesh Ram Chanchali
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I worked on that and what prabhu is telling may be correct as far as my knowledge is concerned
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, thanks for the correction and validation. I can't think of a case where I needed to to this, but it's still good to know the possibility exists.
 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx to all,

For giving the solutions, yes prabhu is telling right that one Connection can have more than one resultset, because same thing is i m using and all resultset are work fine untill you will not close the Connection.
Thanx...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic