keycontainer.java

来自「WAP PUSH后台源码,WAP PUSH后台源码」· Java 代码 · 共 74 行

JAVA
74
字号
package com.tssx.ebiz.common;

import java.sql.*;
/**
 *
 * <p>类名: KeyContainer</p>
 * <p>功能: </p>
 * <p>版权: Copyright (c) 2002</p>
 * <p>公司: 深讯信科</p>
 * @程序 xuke
 * @修改纪录 1.0
 */

public class KeyContainer {

     public static long getNewSequence(String sequenceName) throws KeyException{

          Connection con = null;
          //ConnPoolHandler handler = null;
          long seq=0;
          sequenceName= sequenceName.toUpperCase();
          try
          {
               //handler = ConnPoolHandler.getHandle();
               con = ConnPoolHandler.getConnection();
               seq=getNewSequence(con,sequenceName);
               return seq;
          }
          finally
          {
               ConnPoolHandler.closeConnection(con);
          }
     }

     /**
      * 获得一个唯一的编号,与KeyContainer的大致一样,只是Conn是传进来的
      * Creation date: (2001-9-3 15:26:41)
      * @return long
      * @param tableName java.lang.String
      * @param nStep int
      * @param con java.sql.Connection
      * @exception com.gmcc.portal.common.KeyException The exception description.
      */
     public static long getNewSequence(Connection con,String sequenceName) throws KeyException {

          PreparedStatement stmt = null;
          ResultSet rs = null;
          long seq=0;
          sequenceName= sequenceName.toUpperCase();
          try
          {
               String sql="select "+sequenceName+".nextval as seq from dual";
               stmt = con.prepareStatement(sql);
               rs = stmt.executeQuery();
               if(rs.next()){
                    seq=rs.getLong("seq");
               }
               stmt.close();
               return seq;
          }
          catch(SQLException e){
               System.out.println(e.getMessage());
               throw new KeyException(e.getLocalizedMessage());
          }
          finally{
               try{
                    if(stmt!=null) stmt.close();
               }catch(SQLException e){
                    System.out.println(e.getMessage());
                    throw new KeyException(e.getLocalizedMessage());
               }
          }
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?