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()?
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()?
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.