• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

you have got to solve this ...its intersting

 
anand chawla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well problem guys....
I have developed a kind of online quiz...which works perfectly with single user...but if two requests come at the same time...we face a unsual problem the first person gets this message....
java.sql.SQLException: Invalid state for getResultSet
and the second user gets this message.....
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Function sequence error

well I m surprised at it becoz i have created session object thinking that this conflict wont happen but i m not able to understand this...
can u help me maha anna ,william.....please

 
Matts Smith
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you reusing the same connection and resultset over 2 different requests?
 
anand chawla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Previously i was using the same connection object
but now i m having a connection object for session
do i have to create different resultset and statements for different users
please help
 
Brett Knapik
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should use a connection broker for your database connections you can get one at http://www.javaexchange.com
------------------
In Gates we trust. Yeah right....
 
Richard Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understood your question correctly, then yes, you do need a new ResultSet and Statement instance for each query. If you are "sharing" a ResultSet variable (for example, as an attribute in your Servlet class) the second query will overwrite anything returned by the first query, and who knows what will happen next.
Hope this helps.
- Rick
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to restate one of the most important things about servlet programming. It is very dangerous to have any non-final member variables in a servlet class. If you have any, at all, move them out to somewhere which is not shared betwen requests, or you will face all sorts of wierd faults.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
[...] It is very dangerous to have any non-final member variables in a servlet class. If you have any, at all, move them out [...]

Or, implement SingleThreadModel, but beware of the scalability issues of that. (And, as Frank pointed out elsewhere, your resources such as database connections will eventually time out, so be prepared to check and if necessary resurrect them when servicing a request).

- Peter


[This message has been edited by Peter den Haan (edited March 06, 2001).]
 
Matts Smith
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if it's possible with your appserver but consider using connection pooling. I know it's easy to set up in Websphere and JRun.
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah , this is the problem with Connection object though u can solve with connection pool class which maintains the pool of connection objects. It can be prepared by urself(or search in net for sample code) irrespective of application server u use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic