wood burning stoves*
The moose likes Servlets and the fly likes you have got to solve this ...its intersting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "you have got to solve this ...its intersting" Watch "you have got to solve this ...its intersting" New topic
Author

you have got to solve this ...its intersting

anand chawla
Ranch Hand

Joined: Oct 19, 2000
Posts: 91
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

Joined: Feb 03, 2001
Posts: 113
are you reusing the same connection and resultset over 2 different requests?
anand chawla
Ranch Hand

Joined: Oct 19, 2000
Posts: 91
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

Joined: Oct 15, 2000
Posts: 255
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....


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Richard Harris
Greenhorn

Joined: Mar 06, 2001
Posts: 7
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

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Feb 03, 2001
Posts: 113
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

Joined: Oct 31, 2000
Posts: 527
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.

SCJP 1.5, SCEA, ICED (287,484,486)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: you have got to solve this ...its intersting