[java]201610月小工具

2016-10-12  本文已影响10人  TY_

返回可用id插件

    public int rownum() {
        int num = 0;
        try {
            // 获取数据库
            Connection conn = jdb_utils.getConnection();
            // 执行语句--查询name=?的信息(单列多行)
            //SELECT COUNT(Id) from types where id;
            PreparedStatement pst = conn.prepareStatement(SQL.SQLSTU_ROWNUM);
            // 返回结果
            ResultSet rs = pst.executeQuery();

            while (rs.next()) {
                num = rs.getInt("COUNT(Id)");
            }
            return num + 1;// 返回一个可用id
        } catch (Exception e) {
            throw new RuntimeException("获取失败...");
        }

随机生成8位数字

    public int getuid() {
        int i = 0;
        StringBuilder str = new StringBuilder();
        Random ran = new Random();
        for (int j = 0; j < 8; j++) {
            i = ran.nextInt(10);
            str.append(i);
        }
        i = Integer.parseInt(str.toString());

        return i;

    }

// 获取文件格式
public String substr(String str) {
String name = str.substring(str.length() - 4);
return name;
}

上一篇 下一篇

猜你喜欢

热点阅读