Chinaunix首页 | 论坛 | 博客
  • 博客访问: 272880
  • 博文数量: 53
  • 博客积分: 4010
  • 博客等级: 上校
  • 技术积分: 496
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-06 11:05
文章分类

全部博文(53)

文章存档

2011年(1)

2008年(52)

我的朋友

分类: WINDOWS

2008-03-07 21:17:27

private static String SQL_GETMAXID = "select ident_current('此处是表名') as id";
    private int getMaxID() {
        Connection conn = null;
        PreparedStatement pstmt;
        ResultSet rs;
        int id = 0;
        try {
            conn = cpool.getConnection();//在此处取得与数据库连接
            pstmt = conn.prepareStatement(SQL_GETMAXID);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                id = rs.getInt(1);
            }
            rs.close();
            pstmt.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return id;
    }
阅读(1204) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~