Project

General

Profile

« Previous | Next » 

Revision 1129

Added by Jing Tao over 22 years ago

Using getDBConenction rather than pass connection as parameter.

View differences:

src/edu/ucsb/nceas/dbadapter/SqlserverAdapter.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 MS SQL Server 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 @@IDENTITY");
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
    try
60
    {
61
      //check out DBConnection
62
      conn=DBConnectionPool.getDBConnection("SqlserverAdapter.getUniqueID");
63
      serialNumber=conn.getCheckOutSerialNumber();
64
      stmt = conn.createStatement();
65
      stmt.execute("SELECT @@IDENTITY");
66
      ResultSet rs = stmt.getResultSet();
67
      if ( rs.next() ) {
68
        uniqueid = rs.getLong(1);
69
      }
70
      stmt.close();
60 71
    }
61
    stmt.close();
72
    finally
73
    {
74
      DBConnectionPool.returnDBConnection(conn, serialNumber);
75
    }
62 76
    //System.out.println("Unique ID: " + uniqueid);    
63 77
    return uniqueid;
64 78
  }

Also available in: Unified diff