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

📄 databaseidgenerator.java

📁 这是一本描述JDBC数据库的书籍
💻 JAVA
字号:
/* * DatabaseIDGenerator.java * * Created on 2005年6月9日, 下午7:28 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package oid;import java.sql.*;import common.*;/** * * @author kevin */public class DatabaseIDGenerator {    public final static long ID_TYPE_PERSON = 1;    public final static long ID_TYPE_STUDENT = 11;    public final static long ID_TYPE_EMPLOYEE = 12;        public final static long ID_TYPE_MASTER = 111;    public final static long ID_TYPE_BACHELOR = 112;        public final static long ID_TYPE_MANAGER = 121;    public final static long ID_TYPE_ENGINEER = 122;        public static synchronized long nextPersonID(){        return nextID(ID_TYPE_PERSON);    }        public static synchronized long nextStudentID(){        return nextID(ID_TYPE_STUDENT);    }        public static synchronized long nextEmployeeID(){        return nextID(ID_TYPE_EMPLOYEE);    }        public static synchronized long nextMasterID(){        return nextID(ID_TYPE_MASTER);    }        public static synchronized long nextBachelorID(){        return nextID(ID_TYPE_BACHELOR);    }        public static synchronized long nextManagerID(){        return nextID(ID_TYPE_MANAGER);    }        public static synchronized long nextEngineerID(){        return nextID(ID_TYPE_ENGINEER);    }        private static long nextID(long type){        Connection conn = null;        Statement stmt = null;        ResultSet rs = null;        long nextID = 0;        try{            ConnectionFactory factory = ConnectionFactory.getConnectionFactory();            conn = factory.getConnection();                        String sql = "select nextval from oid_tbl where type=" + type;            stmt = conn.createStatement();                        rs = stmt.executeQuery(sql);            rs.next();            nextID = rs.getLong("nextval");                        String updateSql = "update oid_tbl set nextval = nextval + 1 where type = " + type;            stmt.execute(updateSql);        }catch(Exception e){            e.printStackTrace();        }finally{            DBUtils.close(rs, stmt, conn);        }        return nextID;    }    }

⌨️ 快捷键说明

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