Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jdbc question

Posted on 1998-07-08
2
Medium Priority
?
211 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 20 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

876 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