⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keycontainer.java

📁 JFrame-----java系统通用框架 可以研究一下哦
💻 JAVA
字号:
package com.corp.bisc.ebiz.base;

import javax.ejb.*;
import java.util.*;
import java.awt.*;
import javax.naming.*;

import java.sql.*;
/**
 * Insert the type's description here.
 * Creation date: (4/30/2000 10:18:32 AM)
 * @author: Administrator
 */
public class KeyContainer {

/**
 * KeyContainer constructor comment.
 */
private KeyContainer() {
	super();
}
public static long getNewSequence(Connection conn,String tableName, int nStep)
	throws SQLException{

	if(nStep <= 0){
		throw new SQLException("The parameter of 'nStep' is invalid, it should greater than 0");
		}

	PreparedStatement stmt1 = null;
	PreparedStatement stmt2 = null;
	ResultSet rs = null;
	tableName = tableName.toUpperCase();
	boolean bAutoCommit = false;
	try
	{
		stmt1 = conn.prepareStatement("Select SequenceNo from sequence where domain = ? for update of SequenceNo");
		bAutoCommit = conn.getAutoCommit();
		conn.setAutoCommit(false);

		stmt1.setString(1 , tableName);
//		stmt1.setCursorName("x");
		rs = stmt1.executeQuery();
		String sName = rs.getCursorName();
		rs.next();

		int seq = rs.getInt(1);
		seq = seq + nStep;
		stmt2 = conn.prepareStatement("UPDATE SEQUENCE SET SEQUENCENO = SEQUENCENO + ? WHERE current of " + sName);
		stmt2.setInt(1, nStep);

		stmt2.executeUpdate();
		if(bAutoCommit)
			conn.commit();

		return seq;
	}
	catch(SQLException e){
		if((conn != null) && bAutoCommit)
			conn.rollback();
		throw e;
	}
	finally
	{
		try
		{
			if(conn != null)
				conn.setAutoCommit(bAutoCommit);
			if (stmt1 != null) stmt1.close();
			if (stmt2 != null) stmt2.close();
		}
		catch(Exception e)
		{
				/*
					ignore this exception
				*/
		}
	}
}
/**
 * 此处插入方法描述。
 * 创建日期:(2002-6-19 17:33:43)
 * @return long
 * @param conn java.sql.Connection
 * @param tableName java.lang.String
 * @exception java.lang.Exception 异常说明。
 */
public static long getOracleSequence(Connection conn, String tableName) throws java.sql.SQLException{
	long result = 0;
	String tblname = "seq_"+tableName;
	String sql = "select "+tblname+".nextval from dual";

	Statement stat = conn.createStatement();
	ResultSet rs = stat.executeQuery(sql);
	while(rs.next())
		result = rs.getLong(1);
	stat.close();

	return result;
}
/**
 * 此处插入方法描述。
 * 创建日期:(2002-6-26 11:28:48)
 * @param args java.lang.String[]
 */
public static void main(String[] args) {

}
}

⌨️ 快捷键说明

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