patel sagar
patel sagar

Reputation: 21

which gives performance in java ?storing value in variable then use it or direct use of value from single row.i am getting row from result set?

I am getting value from single row using resultSet. which is better:

Upvotes: 0

Views: 57

Answers (2)

Mustafa sabir
Mustafa sabir

Reputation: 4360

If you read a value multiple times from ResultSet it requires some overhead but since ResultSet uses client side cache the retrieval will be fast. But it is better/faster to store it in a variable and use it, if it is required to be used multiple times (the difference should be very very small). But as chrylis commented, you should not worry about such small performance hacks.

Upvotes: 0

Tomas
Tomas

Reputation: 1323

Reading a value from a ResultSet does not come for free, and if you have to use the value several times you should store it in a local variable instead of re-reading it each time.

Upvotes: 1

Related Questions