📄 identity.java~1~
字号:
package com.lazybug.sql;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.sql.*;
public class Identity
{
public final static String TABLE = "tbl_identity";//序列表的名称
public static int getIdentity(String tblname)
{
int value=-1;
DBConnection dbconn = DBConnectionManager.getConnection();
Connection conn = dbconn.get();
PreparedStatement pstmt = null ;
ResultSet rs = null ;
try
{
String psql = "select tblid from "+TABLE+" where tblname=?" ;
pstmt = conn.prepareStatement(psql) ;
pstmt.setString(1, tblname) ;
rs = pstmt.executeQuery() ;
if ( rs.next() )
{
value = rs.getInt("tblid");
}
rs.close();
String updateSql="update "+TABLE+" set tblid=tblid+1 where tblname=?";
pstmt = conn.prepareStatement(updateSql) ;
pstmt.setString(1,tblname);
pstmt.executeUpdate();
pstmt.close() ;
}
catch (SQLException ex)
{
return -1;
}
finally
{
DBConnectionManager.freeConnection(dbconn);
}
return value;
}
public synchronized static int getSequence(String tablname, String tablekey)
{
int value=-1;
DBConnection dbconn = DBConnectionManager.getConnection();
Connection conn = dbconn.get();
PreparedStatement pstmt = null ;
ResultSet rs = null ;
try
{
String psql = "select max("+tablekey+") from "+tablname;
pstmt = conn.prepareStatement(psql) ;
rs = pstmt.executeQuery() ;
if ( rs.next() )
{
value = rs.getInt(1);
value += 1;
}
rs.close();
pstmt.close() ;
}
catch (SQLException ex)
{
return -1;
}
finally
{
DBConnectionManager.freeConnection(dbconn);
}
return value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -