aspose file tools*
The moose likes JDBC and the fly likes can i append my session varable name to resultset object name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "can i append my session varable name to resultset object name?" Watch "can i append my session varable name to resultset object name?" New topic
Author

can i append my session varable name to resultset object name?

bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
hi frds..
can i append my session varable name to resultset object name?ie

in normal case

ResultSet rstuser;

but in my case:

session = request.getSession(true);
String susername=(String)session.getAttribute("username");

example,assume session username value is dani.then i want resultset object name as like

ResultSet danirstRegister;

it possible?please help..urgent..thanks in advances
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
sorry wrongly type in pervious post.i want as

ResultSet danirstuser
John Pradeep.v
Ranch Hand

Joined: Jul 21, 2008
Posts: 59
Hi Bala,
Could you also mention the need for such an approach? It might be helpful to better understand the problem
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
thanks for your reply john...when many user accessing same java class..resultset value of first request user is showing to other request user...we found session handling good,but we found problem in displaying resultset value for appropriate user.so we feel resultobject based on session username may resolve these problem.what you guys feel?or may other problem?please it urgent issue..waiting for your reply guys..thanks in advances...
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
Bala, i donot think so , you can do this.
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
what may be other way to resolve these problem..?any suggestion..waiting..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

You need to stop thinking about silly solutions and find out why your data is being shared inappropriately across sessions.

It sounds like a threading issue. Are you perhaps using instance variables in a servlet?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
yes am using instance variable.here it my part of my coding

String strAuto="---------------";
PreparedStatement prest=con.prepareStatement(strAuto);
ResultSet Rst=prest.executeQuery();
while(Rst.next())
{
strLastNumber=Rst.getString(1);
}
John Pradeep.v
Ranch Hand

Joined: Jul 21, 2008
Posts: 59
Bala,
You cannot have different variables for different users, this is exactly why session management is used for... I don't know the exact structure/design of your code.. but i think you are not using session properly or you are sharing the instance variable in a servlet or you might have a static variable holding the result set..

can you paste the full class file here?

Regards,
John
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29255
    
140

1) How does that code snippet relate to the session? Do you have some list of active session variables?
2) It is good practice to close the result set quickly. This means looping through it and storing the results in a data structure. That data structure could be stored in the session. Or even a Map with the name as key if you have some reason you can't use a session.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
yes i have...i said abt my session variable in first post itself...i closed my resultset in finally block only.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29255
    
140

bala manian wrote:yes i have...i said abt my session variable in first post itself...i closed my resultset in finally block only.

I don't understand what you are trying to accomplish with the multi-named variables. I don't see that explained in the first post.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

I suspect that the poster is encountering threading issues and is looking in the wrong place to solve it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can i append my session varable name to resultset object name?
 
Similar Threads
setAttribute(String name, Object value) question
String and StringBuffer
What's the purpose of "this" keyword?
OpenSessionInViewFilter does not help, Spring + Hibernate
Problems with java and mysql error: 1064