美文网首页
[java]201610月小工具

[java]201610月小工具

作者: TY_ | 来源:发表于2016-10-12 18:27 被阅读10次

返回可用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;
}

相关文章

网友评论

      本文标题:[java]201610月小工具

      本文链接:https://www.haomeiwen.com/subject/pubiyttx.html