日期:2014-05-20 浏览次数:20830 次
package zujuanxitong;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Helper implements MysqlConfig{
private static Connection conn;
private static Statement stat;
private static ResultSet rs;
int cc;
int temp[];
/*
中间是连接数据库的代码,跟问题无关
*/
public void xuanTi()throws SQLException{
int i=0;
Zongshu bb = new Zongshu();
bb.jiShu();
cc=bb.aa;
//System.out.println(cc);
temp=new int[cc];
String sql = "select ItemID from iteminformation where chapters = '一' ; ";
ResultSet rs = Helper.query(sql);
while(rs.next()){
int num=rs.getInt("ItemID");
temp[i]=num;
System.out.println(temp[i]);
i++;
}
}
}
package zujuanxitong;
import java.sql.SQLException;
import com.mysql.jdbc.ResultSet;
public class Zongshu {
int aa;
public void jiShu() throws SQLException{
String sql="select count(*) from iteminformation where chapters = '一' ;";
ResultSet shu = (ResultSet) Helper.query(sql);
//while(shu.next()){
shu.next();
//System.out.println(shu.getInt(1));
aa = shu.getInt(1);
//System.out.println(aa);
//}
}
}
package zujuanxitong;
import java.util.Random;
public class SuiJiChouTi extends Helper {
int[] intRet = new int[6]; //存放随机数的数组
int dd;
public void chouTi() {
Zongshu bb = new Zongshu();
try{
bb.jiShu();
}catch(Exception e){
e.printStackTrace();
}
dd=bb.aa;//dd为选择的该类试题总数
int intRd = 0; //存放随机数
int count = 0; //记录生成的随机数个数
int flag = 0; //是否已经生成过标志
while(count<6){
Random rdm = new Random(System.currentTimeMillis());
intRd = Math.abs(rdm.nextInt())%dd;//dd为该类试题总数,随机数的范围设定,dd=10意思为 范围是0~9