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