How to pass SQL query using session

Posted on 2003-03-09
Medium Priority
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????
Question by:OwenMania
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

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);

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

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


Author Comment

ID: 8101177
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

Expert Comment

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?
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

ID: 8101197
microsoft sql 2000
LVL 53

Accepted Solution

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

Author Comment

ID: 8107451
oh i will try
thx very much

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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