File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how do i do this urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how do i do this urgent" Watch "how do i do this urgent" New topic
Author

how do i do this urgent

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Nov 03, 2000
Posts: 331
im using microsoft SQL 7.0
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
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

Joined: Jul 09, 2001
Posts: 1879

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i do this urgent