Where does resultset data stored? Either in server or client?

Hi,

I wanted to know the answers for the follwoing queries. If you guys could help me out it would be grateful.

1) When a query is executed and the resultsets are obtained from database where exactly is the result set placed? Is it placed in the server or on the client machine?

2) Also what happens if your query is executed and assume your database is down and when you call rs.next() what happens?

3) Does calling rs.next() makes a call to the database to fetch the next record?

Regards,

Sun

[538 byte] By [EsakkiSundara] at [2007-9-23]
# 1

> Hi,

> I wanted to know the answers for the follwoing

> ng queries. If you guys could help me out it would be

> grateful.

> 1) When a query is executed and the resultsets are

> obtained from database where exactly is the result

> set placed? Is it placed in the server or on the

> client machine?

> 2) Also what happens if your query is executed and

> assume your database is down and when you call

> rs.next() what happens?

> 3) Does calling rs.next() makes a call to the

> database to fetch the next record?

>

> Regards,

> Sun

Short Answers.

1) Depends on driver.

2) Depends on driver.

3) Depends on driver.

Longer Answer

The inner mechanics of scrolling through a result set depend on both the implementing driver and the underlying database.

Any of the following may happen.

a) The driver fetches the entire Result Set and caches it locally.

b) The driver fetches one row at a time, each time that you call next.

c) The driver fetches a bunch ( a somewhat arbitrary number) of rows when you call next()

For the second and third options it should be pointed out that there are of course other cursor moving methods (ie absolute) but the idea is the same.

A "good" driver will in my opinion when the database supports it do (c) and many in fact do. That is why you have the methods like setFetchSize which provide a way for you to hint to the driver how many rows it should fetch at once. The one downside I see with this implementation is that it doesn't work for sensitive cursors. I think sensitive cursors should ALWAYS do (b) meaning fetching the row as you request it.

Anyway back to your questions.

What would happen if the connection to the db was lost halfway through a result set. Well unless the driver is cacheing everything locally it should throw a SQLException. It should not return false if that is what you might have been asking.

Well that was longish so I think I'll stop but I hope it helps.

EsakkiSundara at 2007-7-10 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hi, Thanks for your reply. Your longish your answers gave good idea.
EsakkiSundara at 2007-7-10 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...