wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes y this simple program throws exception?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "y this simple program throws exception??" Watch "y this simple program throws exception??" New topic

y this simple program throws exception??

reehan ishaque
Ranch Hand

Joined: Mar 25, 2001
Posts: 54
hi folks!
im new to jdbc n sending u a very simple program that throws exception "general error accessing database". the program executes fine for the first few iterations but raises exceptions later. i am using oracle server.plz help me in sorting out the error in this program.
thanks n bye

import java.sql.*;
class find{
Connection con;
con=DriverManager.getConnection("jdbc dbc:data","scott","tiger");

}catch(Exception e){System.out.println(e);}
void m()
ResultSet r=null;
PreparedStatement pt=null;
pt = con.prepareStatement("select * from tableName");
}catch(Exception e){System.out.println(e);}
finally {
try {
catch (Exception e) {
public static void main(String args[]){
find f = new find();
for(int i=0;i<=100;i++)
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I think you need to do 1 of 2 things (do one or the other, but not both!):
1. close the prepared statement in your finally block. Each iteration creates a new prepared statement and the memory is not released.
2. make your prepared statement a class variable (along with the connection so it is created only once and reused in each iteration
For more detailed error messages see the new exception handling I've added
performance tip: create the connection once, create the prepared statement once, reuse them in the iteration:

Good luck,
[This message has been edited by Jamie Robertson (edited August 08, 2001).]
[This message has been edited by Jamie Robertson (edited August 08, 2001).]
I agree. Here's the link: http://aspose.com/file-tools
subject: y this simple program throws exception??
It's not a secret anymore!