File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Incrementing primary key

 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • 0
  • 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??
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • 0
  • 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...
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • 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.
 
Scott Selikoff
author
Saloon Keeper
Posts: 3889
15
Eclipse IDE Flex Google Web Toolkit
  • 0
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic