Revision 757
Added by bojilova about 23 years ago
DBOracle.java | ||
---|---|---|
39 | 39 |
* The name of the sequence used to generate the unique id |
40 | 40 |
* is made from the name of the table that uses the id by |
41 | 41 |
* appending "_id_seq" to it. |
42 |
* When record is inserted in the table and before insert trigger |
|
43 |
* gets a nextval from that sequence, select currval of that |
|
44 |
* sequence can return the generated key in the same db connection. |
|
42 | 45 |
* |
43 |
* @param conn db connection in which to generate the unique id
|
|
44 |
* @param tableName the name of table which unique id to generate
|
|
46 |
* @param conn db connection in which the unique id was generated
|
|
47 |
* @param tableName the name of table which unique id was generate
|
|
45 | 48 |
* @exception SQLException <br/> any SQLException that can be thrown |
46 | 49 |
* during the db operation |
47 | 50 |
* @return return the generated unique id as a long type |
... | ... | |
50 | 53 |
throws SQLException { |
51 | 54 |
long uniqueid = 0; |
52 | 55 |
Statement stmt = conn.createStatement(); |
53 |
stmt.execute("SELECT " + tableName + "_id_seq.nextval FROM dual");
|
|
56 |
stmt.execute("SELECT " + tableName + "_id_seq.currval FROM dual");
|
|
54 | 57 |
ResultSet rs = stmt.getResultSet(); |
55 | 58 |
if ( rs.next() ) { |
56 | 59 |
uniqueid = rs.getLong(1); |
Also available in: Unified diff
- new db adapter for MS SQL Server
- changed the getUniqueID(conn, tableName) to return the last generated by the db unique ID
instead of generating unique ID first by the appl and then supplied to the insert,
because SQL Server doesn't have capabilities
unique ID to be generated on the client and then supplied to the insert.