[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to pass SQL query using session

Posted on 2003-03-09
6
Medium Priority
?
171 Views
Last Modified: 2012-05-04
for example, set rs = cn.execute ("select * from employee")
can i put Session("new")= rs ????

if not how do i pass "rs" using Session????
thx
0
Comment
Question by:OwenMania
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:NetWize
ID: 8101136
What language are you talking about?
As I know java best here's the java-answer:

ResultSet is not nessesary Serializable, so you will get into trouble storing that into the session.

The call would be session.setAttribute("result", rs);
but will probably throw an NotSerializable Exception on most servers.

There's another Problem with that:
Until the ResultSet get's closed the Connection to the DB stays open. What happens when the user leaves after you put the rs into the session? The ResultSet will stay open until the session is timed out (after 30 minutes or so), wich could cause problems in your DB.

If you require the results of the request to be stored in the session you could "read out" the rs after execution and store the results of that (the data that you will need) into the session. Maybe use a simple data-holding class for that:

public class myresult implements Serializable {
  String row_1;
  String row_2;
}

Vector results = new Vector();
while(rs.next) {
  myresult r = new myresult();
  r.row_1 = rs.getString(1);
  r.row_2 = rs.getString(2);
  results.add(r);
}

As Vector and your myresult are serializable that should work for you.

Hope it helps (and hope you wanted a java-answer)

Jan
0
 

Author Comment

by:OwenMania
ID: 8101177
ummm
ur java seems like can onli take 2 records onli
wat if i have 1000 records?

do u know how to implement in VB
thx very much for ur time
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8101190
Sorry, I'm not into VB but as it's object oriented it should be almost the same. And yes, the example i gave you supports 2 "rows" of result set, but that's an EXAMPLE. And it supports as many database-lines as you wich.

I guess, "row_1" and "row_2" were dumb names for that. the example would be better like

public class myresult implements Serializable {
 String name;
 String adress;
 [...]
}

But: Maybe ResultSets are serializable in VB. What Server are you running that on?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 

Author Comment

by:OwenMania
ID: 8101197
microsoft sql 2000
thx
0
 
LVL 56

Accepted Solution

by:
Ryan Chong earned 80 total points
ID: 8103471
>>can i put Session("new")= rs ????
I think what maybe you can do is try store the records id, instead of whole data in the recordset/resultset, why? it's bcos it'll cause heavy server -loads as we put all data into the session, so if it's allowed, try use less session variables as much as you can in your application.

So, my idea will be like:

Session("rsID") = Rs("id")

Hope this helps
0
 

Author Comment

by:OwenMania
ID: 8107451
oh i will try
thx very much
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Media Temple is thrilled to announce the launch of our new Partner Program, specifically designed to empower digital agencies and adtech platforms by offering white-glove support and exclusive hosting enhancements to optimize their sites and their c…
The Super Bowl is just days away. Millions of advertising dollars will be spent in just a few hours to drive people to websites around the globe. Optimizing your site in anticipation of a big event like this (and the traffic surges that follow) will…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question