Solved

jdbc question

Posted on 1998-07-08
2
202 Views
Last Modified: 2010-03-30
Hi there,
 
    I am facing a wierd problem dealing with jdbc. I am using normal Statement and PrepareStatement in my question.
My program flow is like ,

{

   Connection con = createConnection();
   Statement stmt = con.CreateStatement();//con is a valid
                                           connection object

   PreparedStatement pstmt = con.prepareStatement(sqry);
 
   Resultset rs1 = stmt.executeQuery(sfirstQry);

   while(rs1.next())
   {

       String data = rs1.getString(1);
       
       pstmt.setString(data);
         
       Resultset rs2 = pstmt.executeQuery();
 
       while(rs2.next())
        {
           String data1 = rs2.getString(1);
           printData(data1);
        }
    }

    stmt.close();
}                                          
   
This program runs fine sometimes, but sometimes it gives invalid statement sql exception. I don't know what I am doing wrong. Can somebody tell me what I am doing wrong??
 
0
Comment
Question by:maha
2 Comments
 
LVL 1

Accepted Solution

by:
vijayakumar earned 10 total points
ID: 1225586
Try to close ResultSet rs2 after use (ie) add rs2.close() line after while(rs2.next()) {} loop.
Also try closing Resultset rs1, and the  PreparedStatement handle pstmt . This should work.
0
 

Author Comment

by:maha
ID: 1225587
Thanx Vijay,

But I have already tried what u have told to. Still it did not work. Sorry for not providing the full code.

And another thing,

I used to close connection object after all happenings. When I commented out that line, it is working fine. Do u think any logic here?? Does the whole jdbs operation work in diff thread than the servlet thread I am running here?

Maha

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question