Solved

jdbc question

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 41
couple of eclipse 5 46
javap not working 8 60
jsp insert to database example 2 47
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 “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…
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 …

830 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