Revision 1127
Added by Jing Tao over 22 years ago
src/edu/ucsb/nceas/dbadapter/OracleAdapter.java | ||
---|---|---|
28 | 28 |
package edu.ucsb.nceas.dbadapter; |
29 | 29 |
|
30 | 30 |
import java.sql.*; |
31 |
import edu.ucsb.nceas.metacat.*; |
|
31 | 32 |
|
32 | 33 |
/** |
33 | 34 |
* The Oracle db adapter implementation. |
... | ... | |
49 | 50 |
* during the db operation |
50 | 51 |
* @return return the generated unique id as a long type |
51 | 52 |
*/ |
52 |
public long getUniqueID(Connection conn, String tableName)
|
|
53 |
public long getUniqueID(String tableName) |
|
53 | 54 |
throws SQLException { |
54 | 55 |
long uniqueid = 0; |
55 |
Statement stmt = conn.createStatement(); |
|
56 |
stmt.execute("SELECT " + tableName + "_id_seq.currval FROM dual"); |
|
57 |
ResultSet rs = stmt.getResultSet(); |
|
58 |
if ( rs.next() ) { |
|
59 |
uniqueid = rs.getLong(1); |
|
56 |
DBConnection conn = null; |
|
57 |
int serialNumber = -1; |
|
58 |
Statement stmt = null; |
|
59 |
|
|
60 |
try |
|
61 |
{ |
|
62 |
//check out DBConnection |
|
63 |
conn=DBConnectionPool.getDBConnection("OracleAdapter.getUniqueID"); |
|
64 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
65 |
stmt = conn.createStatement(); |
|
66 |
stmt.execute("SELECT " + tableName + "_id_seq.currval FROM dual"); |
|
67 |
ResultSet rs = stmt.getResultSet(); |
|
68 |
if ( rs.next() ) { |
|
69 |
uniqueid = rs.getLong(1); |
|
70 |
} |
|
71 |
stmt.close(); |
|
60 | 72 |
} |
61 |
stmt.close(); |
|
73 |
finally |
|
74 |
{ |
|
75 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
76 |
} |
|
62 | 77 |
//System.out.println("Unique ID: " + uniqueid); |
63 | 78 |
return uniqueid; |
64 | 79 |
} |
Also available in: Unified diff
Using getDBConnection method rather than a parameter.