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;
}
阅读(1234) | 评论(0) | 转发(0) |