Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i do this urgent

 
john mattucci
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
 
Jamie Robertson
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic