• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.sql.SQLException: Closed Statement: next

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody please help me instead of frequently changing the forum of my question?

Regards
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic