Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

Is it good practice to use SELECT query using executeUpdate() instead of execute()

Hi Experts,

i want to know table having data or not
in select query i will pass account no dynamically
can i use executeUpdate() for select queries or i have to use execute method

in executeupdate if the table having data it will return>1
else it will return 0.

i have a doubt is it good practive to use or i have to use execute()?
Avatar of mccarl
mccarl
Flag of Australia image

If it even works at all, I'm sure it would be specific to a type of database, i.e. do the same thing on another database and it could fail.

In any case, it won't do what you want. The return value is the count of rows "affected" by the query, but a SELECT doesn't affect any rows, just reads them.


If you don't care about any of the data in the table, then just do

SELECT COUNT(*) FROM accounts WHERE account_no = ?

If you do want the data as well, just read the results of the query as normal and also put a counter in the loop where you read the rows.
Avatar of srikotesh
srikotesh

ASKER

what is the alternative for execute update method

if I use executequery() it vl return result set object.
if I use execute method of statement interface every time it will be compiled.

I just want to know data is present or not

I am preferring executeupdate method why means it return int value.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial