Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

how do i do this urgent

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im storing information in a talble (Invoice), and at
the end; the table is generating a number(Invoice #).
ie im trying to generate an invoice # which is
unique. I know how to save the info, but my problem is
how to retrieve this number. Is there a way to read the
Invoice # column prior to closing.
Thank u for your time
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. If you are using oracle:
you can "select sequence.nextval from dual" then use that number as the primary key in an insert statement(guaranteed not to be duplicated)
2. in the JDK 1.4SE there is a method that upon insert, also returns the autonumber field. I don't know of any drivers that implement this yet though.
3. create an autonumber class that will return a unique number, then insert it.
4. Synchronize your insert block that includes a "select max(invoice_id) from table" after your insert which will return the last inserted record's autonumber/pk field.
Which database are you using?
Jamie
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im using microsoft SQL 7.0
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isnt there a way to call the row u are inserting
information into. That way I can go back and call
the invoice# from this row.
Thank u for yor help
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by john mattucci:
isnt there a way to call the row u are inserting
information into. That way I can go back and call
the invoice# from this row.
Thank u for yor help


There might be a way programmatically:

moveToCurrentRow
public void moveToCurrentRow()
throws SQLException
Moves the cursor to the remembered cursor position, usually the current row. This method has no effect if the cursor is not on the insert row.

but I've always been more of a fan of using strictly SQL statements.
Jamie.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!