Forums Register Login

Retrieve record from DB?

+Pie Number of slices to send: Send
Here in my code i have the operation of getting the Maximum primary key and i have to make use for numbering the persons registering.

QUERY


Here in this query it results as


person_id
5



Then how can i read the value of the person_id in the java program. As i had tried to make use of the getInt(),getString() methods with the result set where it specifies the output as

java.sql.SQLException: No current row in the ResultSet.



I am not sure how to solve this problem.
+Pie Number of slices to send: Send
You have two options:
1) check if rs.next() (where rs is a ResultSet) returns true; if so, read the result, otherwise there are no rows and use 1

2) use "select MAX(person_id) AS MaxID from persons". That will always return a value, possibly NULL. If you use getInt, that NULL will be converted to 0.
+Pie Number of slices to send: Send
I think, you didn't call rs.next() prior getting the result from the set.
+Pie Number of slices to send: Send
Hi,

I got a temporary solution.

Where if i make use of the PreparedStatement then the problem arises that no result set found, but in case if i make use of the ordinary statement it has no problem with retrieving information from the database.

I had used only the rs.next() in while loop no other way the result set values are retrieved.

Can anyone say me what could be the reason for the difference in using these two statements in this situation.
+Pie Number of slices to send: Send
 

Originally posted by Wing Rider:
Where if i make use of the PreparedStatement then the problem arises that no result set found, but in case if i make use of the ordinary statement it has no problem with retrieving information from the database.



Where is the code?
+Pie Number of slices to send: Send
Working Code


Error Code
+Pie Number of slices to send: Send
These are 2 different queries pal. Use the same query with PreparedStatement you will get the result fine.
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 913 times.
Similar Threads
Composite key in collection of basic type
Hibernate nested joined-subclass
errors uploading an image to the database
DAO pattern with link tables - looking for canonical way forward
Repeated updates on EVENT table, in Hibernate one to many mapping
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:48:19.