package newexam;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class AccessJudge {
static String fileName = "d:/cf/015山东轻工业学院_XP_13考场.crp";
static int NUM = 10;
static File outDir = new File("d:/cf");
static File absoluteDir = new File(outDir.getAbsolutePath());
static Connection con = null;
// 类静态方法,完成对数据库连接等初始化工作
static {
if (!absoluteDir.exists()) {
System.out.println("正在创建文件夹");
absoluteDir.mkdirs();
}
}
/**
* 读取数据库中判断题,共10套,并给出答案。判断题表中第三个字段为答案,0代表错,1代表对
*/
public static void getJudge() throws Exception {
DAOAccess dao = new DAOAccess(fileName);
con = dao.getConnection();
Statement stat = con.createStatement();
// 从Judege1表中读取所有记录,并按题号分组,且排序,结果应该是多条记录,它们存放在一个集合中
BufferedWriter out = new BufferedWriter(new FileWriter(new File(
absoluteDir, "Judge.txt")));
int m;
for (m = 1; m <= NUM; m++) {
String sql = "select * from Judge" + m
+ " Group by TestID Order By TestID ";
ResultSet res = stat.executeQuery(sql);
out.newLine();
out.write("***********第" + m + "套题**************");
out.newLine();
// 将数据库中的内容写入Judge.txt文件中
int i = 1; // i为题号
while (res.next()) {
int count = res.getInt(3); // 判断题表中第三个字段为答案,0代表错,1代表对
String s = "(" + ((count == 0) ? "×" : "√") + ")";
out.write(s + i + "." + res.getString(2)); // 第2个字段是题干
out.newLine();
i++;
}
}
stat.close();
out.close();
dao.close();
System.out.println("生成判断题,请检查!");
}
public static void main(String args[]) throws Exception {
getJudge();
}
}