The moose likes JDBC and Relational Databases and the fly likes Incrementing primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Incrementing primary key" Watch "Incrementing primary key" New topic

Incrementing primary key

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
i have a primary key pid in a class called project...

I have a struts action class called createproject action where i set the pid for the project...

so I wrote a query

and i want to go through result set and increment it likewise as:

it's not going into while loop...

When i run the query it works fine

what should be the change??
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Pradeep Adibatla wrote: while(

This doesn't make any sense as your SQL query will yield a single result row...

OCJP 6 (93%)
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
As Lorand said, there is only one record returned every time you run your query. When the if statement is executed, you visit the first row, then the while statement is executed, but since there are no more rows to visit, it will always yield false.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Are you aware isn't a read-only call? Anytime you use it, you move the pointer in the result set. In order to hit the while loop in your code, you'd have to have at least 2 records from the result.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Incrementing primary key
jQuery in Action, 3rd edition