File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes java.sql.SQLException: Closed Statement: next Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: Closed Statement: next" Watch "java.sql.SQLException: Closed Statement: next" New topic
Author

java.sql.SQLException: Closed Statement: next

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
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

Joined: Feb 06, 2008
Posts: 29
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

Joined: Mar 22, 2008
Posts: 732
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

Oops, sent to the wrong forum per accident. Can someone move this to JDBC please?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
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

Joined: Oct 13, 2005
Posts: 38075
    
  22
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

Joined: Mar 22, 2008
Posts: 732
Can anybody please help me instead of frequently changing the forum of my question?

Regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 22, 2008
Posts: 732
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

Joined: Aug 17, 2006
Posts: 81
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

Joined: Mar 22, 2008
Posts: 732
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: Closed Statement: next
 
Similar Threads
Help with Thread.sleep()
How to show progress?
Sending Emails
Date Comparison in Java
Want to convert my code in method