博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

program-life

所有的一切都要靠我自的努力去获得,这样我才能抬起头来做人...... 别人的永远不会是我的......
myprogramlife.cublog.cn


技巧示例->得到刚插入表中的ID
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;
    }

发表于: 2008-03-07 ,修改于: 2008-03-11 10:05,已浏览153次,有评论0条 推荐 投诉


网友评论

发表评论