Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2006, 04:13 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default "OPERATION NOT ALLOWED AFTERRESULT SET IS CLOSED"

the problem is
in my project, i have few pages it will be view by more then one person through intranet. when one are more person trying to acuess the same page at the same time one person is getting "OPERATION NOT ALLOWED AFTERRESULT SET IS CLOSED" error
i had used jsp servlet and bean file in my project
here by i had send my bean file used for database connection


package com.pts.database;
import java.io.*;
import java.sql.*;
import java.net.*;

public class DBCon
{
private static final String DriverClass = "com.mysql.jdbc.Driver";
private static final String CONNECTION_STRING = "jdbc:mysql://";
private static final String PORT = "3306";
private static final String DATABASE = "opts";
private static final String user = "dav";
private static final String pwd="";
private static Connection con = null;
private static Statement stmt = null;
private static Statement stmt2 = null;
private static PreparedStatement pst = null;
private static ResultSet rs = null;
private static int count = 0;

public static void assignCon()
{
    
         String CONNECTION_IP="100.100.100.6";
                try{
            Class.forName(DriverClass).newInstance();
        }
        catch(ClassNotFoundException ce){System.out.println (ce);}
        catch(InstantiationException ie){}
        catch(IllegalAccessException ie1){}

        try
        {
            con = DriverManager.getConnection(CONNECTION_STRING+CONN ECTION_IP+":"+PORT+"/"+DATABASE,user,pwd);
            stmt = con.createStatement();
            stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE,ResultSet.CONCUR_READ_ONLY);
        }catch(SQLException sqle){System.out.println("STMT:"+sqle);}
}
public static ResultSet retrieveFromDB(String sql) throws SQLException
{
        return (stmt.executeQuery(sql));
}
public static ResultSet retrieveScrollDB(String sql) throws SQLException
{
        return (stmt2.executeQuery(sql));
}
public static int updateDB(String sql) throws SQLException
{
        return (stmt.executeUpdate(sql));
}
public static PreparedStatement prepareStmt(String sql) throws SQLException{
pst=con.prepareStatement(sql);
     return pst;
}
public static ResultSet getProjectsList() throws SQLException{
rs=((PreparedStatement)con.prepareStatement("s elect projID,projName from proj_det where delFlag=0 || delFlag IS NULL")).executeQuery();
     return rs;
}

public static Connection getConn() {
     return con;
}
public static Statement getStmt()
{
     return stmt;
}
public static void closeAll() throws SQLException
{
     rs.close();
     stmt.close();
     stmt2.close();
     con.close();
}
}

tellme where to change the code
my database is mysql 4.0
driver is com.mysql.jdbc.Driver
server is Tomcat5.0


bye
with regards
 
Old October 9th, 2006, 08:50 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, it's hard to tell exactly based on the code you provided. I'm suspecting, however, that you r servlets have an DBCon member variable defined in them. That'd be your problem. Servlets should not have member variables because they're shared by multiple threads. If they do, then sometimes the instance variable's gonna be in a closed state when some other thread tries to read its ResultSet.

Jon Emerson
Now working at Google!
http://www.jonemerson.net/
 
Old October 12th, 2006, 12:13 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default



Hi thanks for ur reply... as u said , i am not using DBCon memeber variable in servlets... Just i am calling needed static methods inside servlets as DBCon.assignCon(), DBCon.retrieveFromDB("..."), etc...

so wat can b done for that problem now... can u suggest any alternative... Thanks in advance....


 
Old October 12th, 2006, 03:26 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ohh!!! Sorry, I didn't catch this before.

You shouldn't use statics in this case. By using a static database connection, every thread is sharing the same connection. So when one thread opens the connection, another thread may be closing it immediately afterwards. Instead you want every thread to have a unique database connection... so to start, just remove the static declarations and see how things go.

Later on you probably want to use connection pooling so that database connections don't need to be remade on every request. (Creating database connections is expensive.) If you deploy on JBoss, this is incredibly easy to configure -- just create a mysql-ds.xml file in your /deploy/ directory with something like this inside:

  <local-tx-datasource>


    <jndi-name>JetspeedDS</jndi-name>
    <connection-url>jdbc:mysql://localhost/jetspeed/connection-url>

    <driver-class>com.mysql.jdbc.Driver</driver-class>

    <user-name>root</user-name>
    <password></password>
    <min-pool-size>5</min-pool-size>
    <max-pool-size>20</max-pool-size>
    <idle-timeout-minutes>0</idle-timeout-minutes>
  </local-tx-datasource>

But for now, just try not to share connections between threads! Good luck!

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Operation is not allowed when the object is closed lightmaker Classic ASP Basics 1 June 6th, 2008 12:29 PM
Operation is not allowed when the object is closed kingroon Classic ASP Databases 2 February 5th, 2008 10:29 AM
OPERATION NOT ALLOWED AFTERRESULT SET IS CLOSED" picky Java Databases 0 October 4th, 2006 05:36 AM
Operation is not allowed when the object is closed kah Javascript How-To 2 February 16th, 2005 07:20 AM
operation is not allowed when object is closed shoakat Classic ASP Databases 1 November 26th, 2004 12:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.