没有验证过,大致就是这样吧。for (long c = a; c <= b; c++) {
Statement stmt = null;
stmt = con.createStatement();
String sql = "insert into telepnum values(" + c + ")";
String sql2 = "selecet num table telepnum where num = "+c+"";
ResultSet rs=stmt.executeQuery(sql2);
if(rs.next())continue;//如果查到数据相同的直接continue
isok = stmt.executeUpdate(sql);
if (isok != 1) {
continue;
}
if (stmt != null) {// 必须关闭,否则循环多了会报错
stmt.close();
}
System.out.println(c);
}