kusama
kusama

Reputation: 389

How do I Solve the Database connection?

I have a one problem regarding Database(Oracle 10g). I have developed Web Application in JSP Servlet. now I am Performing testing on it. First I have Faced one problem (i.e. "ORA-01000: maximum open cursors exceeded"). For Solving the problem I was closed every connections in every files (eg: Foo.java and Foo.jsp) where the Database connection is established. For this, I have used the Following code:

finally {
    if(rs1 != null) {
        try {
            rs1.close();
        } catch (SQLException e) { /* ignored */ }
        if(ps2 != null) {
            try {
                ps2.close();
            } catch (SQLException e) { /* ignored */ }
        }
        if(con != null) {
            try {
                con.close();
            } catch (SQLException e) { /* ignored */ }
        }
    }

But now the code gives another problem: Application does not fetch any records from database.

When First time I click linked (Add Menu then it shows all data but when I clicked another linked then all records are vanished.

image 1:

Then after like this.

image 2:

and Show Error java.sql.SQLException: Closed Connection

Upvotes: 0

Views: 62

Answers (1)

Chaitanya Mamidi
Chaitanya Mamidi

Reputation: 53

May be you have defined the connection object out side of the method,for the first time using the connection object it connects to the database and when you click on the link again the same methods gets invoked and the connection object is already closed in finally and hence could not connect to database again causing closed connection Exception.

First thing is to create the connection or prepared statement or statement inside the method and fetch the result set.When again the method is called the connection object is created again with help of connection pool and hence can make successful connection to data base.

Upvotes: 1

Related Questions