p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > JSP Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2006, 05:13 AM
Registered User
 
Join Date: Oct 2006
Location: chennai, tamilnadu, India.
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("sel ect 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 9th, 2006, 09:50 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 12th, 2006, 01:13 AM
Registered User
 
Join Date: Oct 2006
Location: chennai, tamilnadu, India.
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....


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 12th, 2006, 04:26 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 01: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 06: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



All times are GMT -4. The time now is 05:00 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc