?? web158_com_server.java
字號(hào):
else
{
return "noexit";
}
}
catch(Exception e)
{
System.out.print(e.getMessage());
txtinfo.setText("在查詢考生信息是否存在時(shí)操作數(shù)據(jù)庫(kù)失敗");
return "error";
}
}
//生成試卷
public boolean createExam(String id)
{
ResultSet rs=null;
//要生成的sql語(yǔ)句
String sql="";
int i=1;
//如果數(shù)據(jù)庫(kù)中存在要選的題數(shù)
if(getExamNum("stu_question_choose")<choose_num||getExamNum("stu_question_operation")<operate_num)
{
System.out.print(getExamNum("stu_question_choose"));
System.out.print(getExamNum("stu_question_operation"));
if(alertnotgo==false)
{
txtinfo.setText("題庫(kù)存量不足,不能考試");
}
return false;
}
try
{
sql="select top "+choose_num+" * from stu_question_choose order by newid()";
//txtinfo.setText(txtinfo.getText()+"\n生成選擇的sql"+sql);
delTemp();
rs=db.getResult(sql);
while(rs.next())
{
//System.out.println(rs.getString(2));
//生成試卷
sql="insert into exam (id,question,a,b,c,d,answer) values("+i+",'"+rs.getString("question")+"','"+rs.getString("a")+"','"+rs.getString("b")+"','"+rs.getString("c")+"','"+rs.getString("d")+"','"+rs.getString("answer")+"')";
//插入不成功返回失敗
if(!makeShijuan(sql))
{
return false;
}
//題ID加一
i++;
System.out.print(sql+"\n");
//txtinfo.setText(txtinfo.getText()+sql);
}
sql="select top "+operate_num+" * from stu_question_operation order by newid()";
//txtinfo.setText(txtinfo.getText()+"\n生成操作的sql"+sql);
rs=db.getResult(sql);
while(rs.next())
{
//System.out.println(rs.getString(2));
//生成試卷
sql="insert into operate (id,question) values("+i+",'"+rs.getString("question")+"')";
//插入不成功返回失敗
if(!makeShijuan(sql))
{
return false;
}
//題ID加一
i++;
System.out.print(sql+"\n");
//txtinfo.setText(txtinfo.getText()+sql);
}
db.Close();
return true;
}catch(Exception e)
{
db.Close();
System.out.print(e.getMessage());
txtinfo.setText(txtinfo.getText()+"在隨機(jī)生成試卷時(shí)操作數(shù)據(jù)庫(kù)失敗");
return false;
}
}//end of createExam
//向臨時(shí)表添加試題
public boolean makeShijuan(String sql)
{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String dbUrl="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=web158_com_config/temp.dll";
Statement stmt=null;
Connection conn=null;
//加載驅(qū)動(dòng)
//**************************
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException nofound)
{
System.err.println(nofound.getMessage());
txtinfo.setText(txtinfo.getText()+"生成試卷Access驅(qū)動(dòng)錯(cuò)誤");
txtinfo.setText(txtinfo.getText()+"生成試卷的SQL"+sql);
return false;
}
//開(kāi)始添加試題
//**********************************
try{
conn=DriverManager.getConnection(dbUrl,"web158.com","web158.com");
stmt=conn.createStatement();
//清空原來(lái)題
//stmt.executeUpdate("delete from exam ");
stmt.executeUpdate(sql);
//關(guān)閉連接
stmt.close();
conn.close();
return true;
}
catch(Exception ef)
{
txtinfo.setText("隨機(jī)生成考生試卷時(shí)操作臨時(shí)數(shù)據(jù)庫(kù)失敗");
return false;
}
finally
{
try
{
stmt.close();
conn.close();
}catch(Exception ef)
{}
}
}
//刪除臨時(shí)表
public boolean delTemp()
{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String dbUrl="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=web158_com_config/temp.dll";
Statement stmt=null;
Connection conn=null;
//加載驅(qū)動(dòng)
//**************************
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException nofound)
{
System.err.println(nofound.getMessage());
return false;
}
//開(kāi)始添加試題
//**********************************
try{
conn=DriverManager.getConnection(dbUrl,"web158.com","web158.com");
stmt=conn.createStatement();
//清空原來(lái)題
stmt.executeUpdate("delete from exam ");
stmt.executeUpdate("delete from operate ");
//關(guān)閉連接
stmt.close();
conn.close();
return true;
}//有錯(cuò)誤
catch(Exception ef)
{
txtinfo.setText(ef.getMessage());
return false;
}//最后
finally
{
try
{
stmt.close();
conn.close();
}catch(Exception ef)
{
}
}
}
//更新已經(jīng)取走試卷的學(xué)生
public boolean updateStuGet(String id)
{
try
{
boolean upok=db.executeSql("update stu_list set examed='true' where stuid='"+id+"'");
db.Close();
if(upok)
{
return true;
}
else
{
return false;
}
}catch(Exception ef)
{
db.Close();
System.out.print(ef.getMessage());
txtinfo.setText("在更新領(lǐng)取試卷學(xué)生信息時(shí)操作數(shù)據(jù)庫(kù)失敗");
return false;
}
}
//更新已經(jīng)取走試卷的學(xué)生
public boolean updateSubmit(String id)
{
//System.out.println("update stu_list set submited='true' where stuid='"+id+"'");
try
{
boolean upok=db.executeSql("update stu_list set submited='true' where stuid='"+id+"'");
db.Close();
if(upok)
{
return true;
}
else
{
return false;
}
}catch(Exception ef)
{
db.Close();
System.out.print(ef.getMessage());
txtinfo.setText("在更新提交試卷學(xué)生信息時(shí)操作數(shù)據(jù)庫(kù)失敗");
return false;
}
}
//更新學(xué)生成績(jī)表
//更新已經(jīng)取走試卷的學(xué)生
public String updateScore(String id,String score)
{
try
{
String sql="update stu_list set stuscore="+score+" where stuid='"+id+"'";
//System.out.println(sql);
boolean upok=db.executeSql(sql);
db.Close();
if(upok)
{
//System.out.println("更新成功");
return "true";
}
else
{
return "false";
}
}catch(Exception ef)
{
db.Close();
System.out.print(ef.getMessage());
txtinfo.setText("在更新學(xué)生選擇題成績(jī)時(shí)操作數(shù)據(jù)庫(kù)失敗");
return "false";
}
}
//查看數(shù)據(jù)庫(kù)中有多少條記錄
public int getExamNum(String examclass)
{
try
{
int num=0;
ResultSet rs=db.getResult("select * from "+examclass+"");
if(rs.next())
{
rs.last();
//取得記錄數(shù)
num = rs.getRow();
}
db.Close();
return num;
}catch(Exception ef)
{
db.Close();
System.out.print(ef.getMessage());
txtinfo.setText("在查看數(shù)據(jù)中存在多少條記錄時(shí)失敗");
return 0;
}
}
//跳轉(zhuǎn)到考生信息面板
void goStuinfo()
{
//添加主體
web158_com_Cpanel.removeAll();
web158_com_Cpanel.add(stulist);
web158_com_Cpanel.repaint();
web158_com_Cpanel.validate();
}
//跳轉(zhuǎn)到試題面板
void goExaminfo()
{
//添加主體
web158_com_Cpanel.removeAll();
//web158_com_Cpanel.add(stulist);
web158_com_Cpanel.repaint();
web158_com_Cpanel.validate();
}
//跳轉(zhuǎn)到配置參數(shù)面板
void goInfoinfo()
{
//添加主體
web158_com_Cpanel.removeAll();
//web158_com_Cpanel.add(stulist);
web158_com_Cpanel.repaint();
web158_com_Cpanel.validate();
}
//跳轉(zhuǎn)到幫助面板
void goHelpinfo()
{
//添加主體
web158_com_Cpanel.removeAll();
//web158_com_Cpanel.add(stulist);
web158_com_Cpanel.repaint();
web158_com_Cpanel.validate();
}
}
//程序入口
public class Web158_Com_Server {
//點(diǎn)位
static Point origin = new Point();
//主入口
public static void main(String[] args) {
//創(chuàng)建窗口對(duì)象
final web158_frame frame=new web158_frame();
//添加窗口移動(dòng)事件
frame.addMouseListener (new MouseAdapter() {
public void mousePressed(MouseEvent e) {
origin.x = e.getX();origin.y = e.getY();
}
});//end of frame.addMouseListener ()
//可以拖動(dòng)
frame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = frame.getLocation();
frame.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y );
}
});//end of frame.addMouseMotionListener()
frame.web158_com_help.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
frame.setExtendedState(Frame.ICONIFIED|frame.getExtendedState());
}
});
//窗口移動(dòng)事件完畢
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -