package com.gton.bean.db;
import java.io.PrintWriter;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import com.gton.bean.util.DB_Conn;
import com.gton.bean.Bean.*;
public class DataBean
{
//private Connection conn=null;
//public Statement sm=null;
private PrintWriter out = null;
ResultSet rs=null;
DB_Conn db_conn=new DB_Conn();;
//private testBean tb;
////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Student登录方法/////////////////////////////////////////////////
public String checkStudentLogin(String name,String number)
{
db_conn.ConnectDB();
try
{
String sql="select * from 学生 where 准考证号='"+number.trim()+"' and 姓名='" + name.trim()+"'";
rs=db_conn.sm.executeQuery(sql); // 执行sql语句
if(rs.next())
return "1";
else
return "0";
}
catch (SQLException SqlE)
{
SqlE.printStackTrace();
return "0";
}
catch (Exception E)
{
E.printStackTrace();
return "0";
}
finally
{
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////调用存储过程/////////////////////////////////////////////////
public String call_procedure_chouti(String Number)
{
String procedure_name="pro_ChouTi";
String call_procedure_string="{call "+procedure_name+"(?,?)}";
Connection conn=null;
String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=exam";
String dbUser="examuser";
String dbPwd="user";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:Exam");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//conn=DriverManager.getConnection(dbUrl,dbUser,dbPwd);
CallableStatement callable_statment=conn.prepareCall(call_procedure_string);
callable_statment.setString(1, Number);
callable_statment.registerOutParameter(2, Types.CHAR);
callable_statment.execute();
String rtn=callable_statment.getString(2);
// conn.commit();
//out.print(rtn);
if( rtn.equals("9")){return "9" ;}//"该生已经在考试!"
callable_statment.close();
return "1";//试卷自动生成!
}
catch(Exception e)
{
e.printStackTrace();
out.print("数据库连接失败!");
return "0";//数据库连接失败!
}
finally
{
try
{
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
out.print("数据库连接失败!");
}
}
}
//********************************************************************
//************从试卷设置表里,取考试时间***********************************
//********************************************************************
public int getTestTime()
{
db_conn.ConnectDB();
try
{
String sql ="select 考试时间 from 试卷设置";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
int test_time=rs.getInt("考试时间");
return test_time;
}
}catch(Exception e)
{
e.printStackTrace();
out.print("数据库操作失败!");
}
db_conn.CloseDB();
return 60;//缺省为60分钟
}
//********************************************************************
//************取各题型分值 *********************************************
//********************************************************************
public int getTxScore(String tx)
{
db_conn.ConnectDB();
try
{
String sql ="select 分值 from 分值设置 where 题型='"+tx+"'";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
int score=rs.getInt("分值");
return score;
}
}catch(Exception e)
{
e.printStackTrace();
out.print("数据库操作失败!");
}
db_conn.CloseDB();
return 1;
}
//********************************************************************
//************取考生考试起始时间 *********************************************
//********************************************************************
public long getStuSTime(String zkz)
{
long dt;
db_conn.ConnectDB();
try
{
String sql ="select 开始时间 from 时间管理 where 准考证号='"+zkz+"' and 考试标志='1'";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
dt=rs.getTimestamp("开始时间").getTime();
return dt;
}
}catch(Exception e)
{
e.printStackTrace();
out.print("数据库操作失败!");
}
db_conn.CloseDB();
dt=new java.util.Date().getTime();
return dt ;
}
//取各题型题数
public int[] getTxNumber()
{
int nums[] ={0,0,0,0};
db_conn.ConnectDB();
try
{
String sql ="select 单选题数,多选题数,判断题数,编程题数 from 试卷设置";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
nums[0]=rs.getInt("单选题数");
nums[1]=rs.getInt("多选题数");
nums[2]=rs.getInt("判断题数");
nums[3]=rs.getInt("编程题数");
return nums;
}
}catch(Exception e)
{
e.printStackTrace();
out.print("数据库操作失败!");
}
db_conn.CloseDB();
return nums;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////取单选题/////////////////////////////////////////////////
public ArrayList getTestList1(String Number)
{
ArrayList list = new ArrayList();
db_conn.ConnectDB();
try
{
String sql ="select * from 试卷 where 题型='1' and 准考证号='"+Number+"' order by NEWID()";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
test1Bean tb = new test1Bean();
tb.setTest_number(rs.getInt("题号"));
tb.setTest_Title(rs.getString("题目").trim());
tb.setTest_A(rs.getString("a").trim());
tb.setTest_B(rs.getString("b").trim());
tb.setTest_C(rs.getString("c").trim());
tb.setTest_D(rs.getString("d").trim());
list.add(tb);
}
}
catch(Exception e)
{
e.printStackTrace();
out.print("数据库连接失败!");
}
return list;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////取多选题/////////////////////////////////////////////////
public ArrayList getTestList2(String Number)
{
ArrayList list = new ArrayList();
db_conn.ConnectDB();
try
{
String sql ="select * from 试卷 where 题型='2' and 准考证号='"+Number+"' order by NEWID()";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
test2Bean tb = new test2Bean();
tb.setTest_number(rs.getInt("题号"));
tb.setTest_Title(rs.getString("题目").trim());
tb.setTest_A(rs.getString("a").trim());
tb.setTest_B(rs.getString("b").trim());
tb.setTest_C(rs.getString("c").trim());
tb.setTest_D(rs.getString("d").trim());
list.add(tb);
}
}
catch(Exception e)
{
e.printStackTrace();
out.print("数据库连接失败!");
}
return list;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////取判断题/////////////////////////////////////////////////
public ArrayList getTestList3(String Number)
{
ArrayList list = new ArrayList();
db_conn.ConnectDB();
try
{
String sql ="select * from 试卷 where 题型='3' and 准考证号='"+Number+"' order by NEWID()";
rs=db_conn.sm.executeQuery(sql);
while(rs.next())
{
test3Bean tb = new test3Bean();
tb.setTest_number(rs.getInt("题号"));
tb.setTest_Title(rs.getString("题目").trim());
list.add(tb);
}
}
catch(Exception e)
{
e.printStackTrace();
out.print("数据库连接失败!");
}
return list;
}
//////////////////////
- 1
- 2
前往页