eatSleepCode
eatSleepCode

Reputation: 4637

Row storage location in Resultset

What happens upon executing statement? does it retrieves all the rows into memory?Where the rows are stored in the Resultset, and how they are fetched into java program?

Update

On calling resultSet.next(); Does it goes to database fetch a singleRow come back at java side and display it? and ResultSet has cursor is it similar to database cursor?

Upvotes: 1

Views: 56

Answers (2)

Nathan Hughes
Nathan Hughes

Reputation: 96385

A common misunderstanding is that the ResultSet must be some kind of container that holds all the rows from the query, so that people try to pass it around the application and are surprised that it becomes invalid when the database connection used to create it closes. The ResultSet is more like a database cursor, it's something you use to pull rows back from the database. The ResultSet has a fetch size that suggests to the driver how many rows it can get from the server at a time, so that it can retrieve the rows in chunks and buffer them for when they're needed.

Upvotes: 1

sibnick
sibnick

Reputation: 4305

It is driver specific. E.g. Postgres JDBC loads all rows by default to memory, Oracle uses cursor on server side and fetches only part of rows.

Upvotes: 1

Related Questions