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

📄 hlidgenerator.java

📁 这是一本描述JDBC数据库的书籍
💻 JAVA
字号:
/* * HLIDGenerator.java * * Created on June 10, 2005, 11:25 AM * * 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 ch02.oid;import java.sql.*;import javax.sql.*;import common.*;import java.util.*;/** * * @author kevin */public class HLIDGenerator {    private static Map idMap = new HashMap();        private static long personID = 1;    private static long studentID = 1;    private static long employeeID = 1;        public static synchronized String nextPersonID(){        String id = (String)idMap.get("PERSON");        if(id == null){            id = nextID();            idMap.put("PERSON", id);        }        id += personID;        personID ++;        return id;    }        public static synchronized String nextStudentID(){        String id = (String)idMap.get("STUDENT");        if(id == null){            id = nextID();            idMap.put("STUDENT", id);        }        id += studentID;        studentID ++;        return id;            }        public static synchronized String nextEmployeeID(){        String id = (String)idMap.get("EMPLOYEE");        if(id == null){            id = nextID();            idMap.put("EMPLOYEE", id);        }        id += employeeID;        employeeID ++;        return id;            }       private static synchronized String nextID(){        Connection conn = null;        Statement  stmt = null;        ResultSet  rs = null;        String     result = null;        try{            ConnectionFactory factory = ConnectionFactory.getConnectionFactory();            conn = factory.getConnection();            stmt = conn.createStatement();            String sql = "select nextval from oid_hl_tbl";            rs = stmt.executeQuery(sql);            long id = 0;            if(rs.next()){                id = rs.getLong("nextval");            }            result = String.valueOf(id);            String updateSql = "update oid_hl_tbl set nextval = nextval + 1";            stmt.executeUpdate(updateSql);        }catch(Exception e){            e.printStackTrace();        }finally{            DBUtils.close(rs, stmt, conn);        }        return result;    }}

⌨️ 快捷键说明

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