|
|
 |
| 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.
|
 |

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
|
|
"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
|

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
|
|
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/
|

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
|
|
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....
|

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
|
|
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/
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |