Solved

jdbc question

Posted on 1998-07-08
2
200 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now