Project

General

Profile

« Previous | Next » 

Revision 1135

Added by Jing Tao over 22 years ago

Change back to pass connection as parameter.

View differences:

src/edu/ucsb/nceas/dbadapter/PostgresqlAdapter.java
50 50
   *            during the db operation
51 51
   * @return return the generated unique id as a long type
52 52
   */
53
  public long getUniqueID(String tableName) 
53
  public long getUniqueID(Connection conn, String tableName) 
54 54
                                         throws SQLException {
55 55
    long uniqueid = 0;
56
    DBConnection conn = null;
57
    int serialNumber = -1;
58 56
    Statement stmt = null;
59
    try
60
    {
61
      //check out DBConnection
62
      conn=DBConnectionPool.getDBConnection("PostgresqlAdapter.getUniqueID");
63
      serialNumber=conn.getCheckOutSerialNumber();
64
      stmt = conn.createStatement();
65
      stmt.execute("SELECT currval('" + tableName + "_id_seq')");
66
      ResultSet rs = stmt.getResultSet();
67
      if ( rs.next() ) 
68
		  {
57
    stmt = conn.createStatement();
58
    stmt.execute("SELECT currval('" + tableName + "_id_seq')");
59
    ResultSet rs = stmt.getResultSet();
60
    if ( rs.next() ) 
61
	  {
69 62
        uniqueid = rs.getLong(1);
70
      }
71
      stmt.close();
72
    }//try
73
    finally
74
    {
75
      DBConnectionPool.returnDBConnection(conn, serialNumber);
76
    }//finally
77
      //System.out.println("Unique ID: " + uniqueid);    
63
    }
64
    stmt.close();
65
 
78 66
    return uniqueid;
79 67
  }
80 68

  

Also available in: Unified diff