• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: Closed Statement: next

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check the following code its giving the error "java.sql.SQLException: Closed Statement: next"


[ October 16, 2008: Message edited by: Farakh khan ]
 
sridhar Ranganathan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have tested your above code with Ms-Access,Its working fine.
If your getting the error still,you can try this manner.
<CODE>

String id[]=new String[];
int cnt=0;
while(rs.next())
{
cnt++;
id[cnt]=rs.getString(1);
}

for(int i=0;i<id.length();i++)
{
PreparedStatement ps1=conn.prepareStatement(query14);
ps1.setString(1, id[i]);
rs1=ps1.executeQuery();

while(rs1.next())
{
emails=rs1.getString(1);
if(emails==null || emails.equals(""))
{
emails="";

}else
{
sendEmail.send("news@mydomain.com", emails, subject, mailmsg); }
}
ps1.close();
}
</CODE>


Thanks,
Sridhar.R
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get category in first resultset and in next resultset trying to get this category emails.

regards
[ October 16, 2008: Message edited by: Farakh khan ]
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, sent to the wrong forum per accident. Can someone move this to JDBC please?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
Oops, sent to the wrong forum per accident. Can someone move this to JDBC please?


may be
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
Oops, sent to the wrong forum per accident. Can someone move this to JDBC please?


Only for you, Rob.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please help me instead of frequently changing the forum of my question?

Regards
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help yourself and us by providing useful details like the stack trace and by telling us which line of code throws the exception.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

The information that I provided in my first post is not enough?

ps1.close(); is creating problem by throwing error

Thanks again & kind regards
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im pretty sure your issue is that you are in a result set, looping and creating new statement(s) and new result set(s) within the loop. Meaning, within rs.next(). Not to be "unhelpful" I didnt look super closely, but I think thats your issue. You cant do that.

If you need to retreive data, then use this data to retrieve something else in a loop, create two sections of code, one that retreives the criteria and stores it in say an ArrayList, then close and clean up your statements and result sets and start a new loop thru the ArrayList doing your second set of SQL. Be sure to clean up as you loop around each time.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic