Solved

jdbc question

Posted on 1998-07-08
2
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

617 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