wood burning stoves 2.0*
The moose likes JDBC and the fly likes problem with result set,if multiple users access  the application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with result set,if multiple users access  the application" Watch "problem with result set,if multiple users access  the application" New topic
Author

problem with result set,if multiple users access the application

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
Hi all!!
I have made a web based application(servlets & jsp pages) which runs fine if accessed from a single m/c.
but if muliple users(even if two) happen to access the application, it causes result set errors e.g. result set is closed or invalid cursor state exception etc
please throw some light...
thanks in advance
Lusha
Amit Agrawal
Ranch Hand

Joined: Aug 23, 2001
Posts: 282
Please check if same Statement is being used by both the users.
I mean see if you are doing connection.createStatement() at some heigher level and Statement.executeQuery() in some particular method which is being accesed by multiple users.
If yes, try after taking your connection.createStatement() inside the method.
lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
Thanks Amit for the prompt reply.
but no methods are involved in the picture as all are jsp files.
see,if u can guide sth. further..
thanks & regards
Lusha
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Sounds like you're saving your database objects as instance variables and that your servlets are not thread safe.
But hard to make a fix in the dark though, do we get to see any code?

Dave.
lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
Hi all!
thanks for ur concern in solving out my query.
as u asked for the code, i don't know how best i can represent it to u, as it's very easy easy to get confused with the project specific intricacies & database details.
few points i would like to mention....
1. i don't know, what do u mean by "thread safe sevlet" or jsp page for that metter (and i only know that web server takes care of it by itself.)please throw some light if u think it can help me...
2. i haven't closed my resultset object anywhere in the whole file (as if i go about doing that then tomcat causes even more problem.)
i mean i haven't used the folowing code anywhere in the file
resultset1.close();
resultset2.close();
statement1.close();
statement1.close();
conn.close();
now here is my code sample............................
ur help is very much required....
Thanks in advance
lusha
//my code sample............................starts here
<%response.setContentType("text/html");<br /> response.setDateHeader("Expires",0);<br /> response.setHeader("Cache-Control","no-cache");<br /> response.setHeader("Pragma","no-cache");<br /> %>

<%@ page language='java' import='java.sql.*,javax.servlet.*,javax.servlet.http.*,java.io.*,java.sql.*,java.util.*' %><br /> <HTML><br /> <HEAD><br /> </HEAD><br /> <%<br /> HttpSession mysession=request.getSession(true);<br /> String user_type= (String)mysession.getValue("ut");<br /> //the following code checks for the vaidity of session<br /> if(mysession.isNew()| |(user_type==null))<br /> {<br /> //if invalid print "u have already logged out" on the terminal<br /> %><br /> <body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF"><br /> <br /> <center><h4>You have already logged out !</h4></center><br /> </body><br /> </html><br /> <%<br /> mysession.invalidate();<br /> }<br /> else<br /> {<br /> //if valid session do the folowing procesing<br /> %><br /> <body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF"><br /> <FORM name="frm" METHOD=POST ACTION="/ExamEngine/eval_paper.jsp"><br /> <%! <br /> //database objects declarations<br /> Connection conn=null;<br /> ResultSet resultset1=null;<br /> ResultSet resultset2=null;<br /> Statement statement1=null;<br /> Statement statement2=null;<br /> //other instance variable declarations such as<br /> String exam_cand_id;<br /> %><br /> <%<br /> //get value from session variable such as<br /> exam_cand_id = (String)mysession.getValue("exam_cand_id");<br /> %><br /> <br /> <%<br /> //database connection code<br /> <br /> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br /> conn=DriverManager.getConnection("jdbc dbc:ex_eng", "sa", "");<br /> statement1=conn.createStatement();<br /> statement2=conn.createStatement();<br /> <br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some select query statemnt with "statement2","resultset2"<br /> //value retrieval from "resultset2"<br /> <br /> <br /> %><br /> <%<br /> }//end of else<br /> %><br /> [This message has been edited by lusha tak (edited September 22, 2001).]<br /> [This message has been edited by lusha tak (edited September 22, 2001).]
lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
trying submit my code sample again...
thanks
lusha
<%response.setContentType("text/html");<br /> response.setDateHeader("Expires",0);<br /> response.setHeader("Cache-Control","no-cache");<br /> response.setHeader("Pragma","no-cache");<br /> %>

<%@ page language='java' import='java.sql.*,javax.servlet.*,javax.servlet.http.*,java.io.*,java.sql.*,java.util.*' %>
<HTML>
<HEAD>
</HEAD>
<%<br /> HttpSession mysession=request.getSession(true);<br /> String user_type= (String)mysession.getValue("ut");<br /> //the following code checks for the vaidity of session<br /> if(mysession.isNew()| |(user_type==null))<br /> {<br /> //if invalid print "u have already logged out" on the terminal<br /> %>
<body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF">


<center><h4>You have already logged out !</h4></center>
</body>
</html>
<%<br /> mysession.invalidate();<br /> }<br /> else<br /> {<br /> //if valid session do the folowing procesing<br /> %>
<body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF">
<FORM name="frm" METHOD=POST ACTION="/ExamEngine/eval_paper.jsp">
<%! <br /> //database objects declarations<br /> Connection conn=null;<br /> ResultSet resultset1=null;<br /> ResultSet resultset2=null;<br /> Statement statement1=null;<br /> Statement statement2=null;<br /> //other instance variable declarations such as<br /> String exam_cand_id;<br /> %>
<%<br /> //get value from session variable such as<br /> exam_cand_id = (String)mysession.getValue("exam_cand_id");<br /> %>

<%<br /> //database connection code<br /> <br /> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br /> conn=DriverManager.getConnection("jdbc dbc:ex_eng", "sa", "");<br /> statement1=conn.createStatement();<br /> statement2=conn.createStatement();<br /> <br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some select query statemnt with "statement2","resultset2"<br /> //value retrieval from "resultset2"<br /> <br /> <br /> %>
<%<br /> }//end of else<br /> %>
lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
javaranch is behaving strange today..
trying again tosubmit my code sample ....
<%response.setContentType("text/html");<br /> response.setDateHeader("Expires",0);<br /> response.setHeader("Cache-Control","no-cache");<br /> response.setHeader("Pragma","no-cache");<br /> %>

<%@ page language='java' import='java.sql.*,javax.servlet.*,javax.servlet.http.*,java.io.*,java.sql.*,java.util.*' %>
<HTML>
<HEAD>
</HEAD>
<%<br /> HttpSession mysession=request.getSession(true);<br /> String user_type= (String)mysession.getValue("ut");<br /> //the following code checks for the vaidity of session<br /> if(mysession.isNew()| |(user_type==null))<br /> {<br /> //if invalid print "u have already logged out" on the terminal<br /> %>
<body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF">


<center><h4>You have already logged out !</h4></center>
</body>
</html>
<%<br /> mysession.invalidate();<br /> }<br /> else<br /> {<br /> //if valid session do the folowing procesing<br /> %>
<body bgcolor="#CCCC99" text="#333300" topmargin="0" leftmargin="0" marginheight=0 marginwidth=0 link="#FFFFFF" vlink="#FFFFFF">
<FORM name="frm" METHOD=POST ACTION="/ExamEngine/eval_paper.jsp">
<%! <br /> //database objects declarations<br /> Connection conn=null;<br /> ResultSet resultset1=null;<br /> ResultSet resultset2=null;<br /> Statement statement1=null;<br /> Statement statement2=null;<br /> //other instance variable declarations such as<br /> String exam_cand_id;<br /> %>
<%<br /> //get value from session variable such as<br /> exam_cand_id = (String)mysession.getValue("exam_cand_id");<br /> %>

<%<br /> //database connection code<br /> <br /> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br /> conn=DriverManager.getConnection("jdbc dbc:ex_eng", "sa", "");<br /> statement1=conn.createStatement();<br /> statement2=conn.createStatement();<br /> <br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some update statemnet with statement object "statement1"<br /> //here some select query statemnt with "statement1","resultset1"<br /> //retreiving values from "resultset1"<br /> //here some select query statemnt with "statement2","resultset2"<br /> //value retrieval from "resultset2"<br /> <br /> <br /> %>
<%<br /> }//end of else<br /> %>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with result set,if multiple users access the application