Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with result set,if multiple users access the application

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 /> %>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic