• Post Reply Bookmark Topic Watch Topic
  • New Topic

Incrementing primary key  RSS feed

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pradeep Adibatla wrote: while(rs.next())



This doesn't make any sense as your SQL query will yield a single result row...
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you aware rs.next() 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!