<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="java.util.*" import="java.lang.*"%>
<%request.setCharacterEncoding("gb2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>准备答题</title>
<link href="img/cssexamin.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript" src="/myside/examin/img/youno.js"></script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
.unnamed1 {
font-size: 12px;
color: #FF0000;
text-decoration: none;
}
-->
</style>
</head>
<body>
<div align="center">
<jsp:useBean id="linejdbc" scope="page" class="examinline.DBConnectionBean" />
<%
String userNow = request.getParameter("userid");
String password=request.getParameter("password");
System.out.print(password);
%>
<%linejdbc.setdrivername();%>
<%
//通过传来的ID提取学生资料
Connection conn = linejdbc.getopenConnection();
PreparedStatement s = conn.prepareStatement
("select * from student where S_id=? and S_psw=?");
s.setString(1,userNow);
s.setString(2,password);
ResultSet result = s.executeQuery();
if (result.next())
{
String S_id = result.getString("S_id");
String S_name = result.getString("S_name");
String Sex=result.getString("sex");
String Major=result.getString("major");
String Grade=result.getString("grade");
%>
<%/*
//随机在学生所要考的科目中提取题库的ID
int romad = 0;
int t = 0;
int i = 0;
Connection connn = linejdbc.getopenConnection();
PreparedStatement p = connn.prepareStatement
("select MAX(id) from quiz ");
ResultSet resultp = p.executeQuery();
resultp.next();
t = resultp.getInt(1);
Random rand = new Random();
i = rand.nextInt(t);
romad = i + 1;
*/
%>
<form action="begin.jsp" method="post" name="formzhunbei" id="formzhunbei">
<span class="unnamed1">登陆成功!</span>
<table width="360" border="0" cellpadding="0" cellspacing="2" >
<tr>
<td colspan="2"><p class="table">您的相关信息:</p></td>
</tr>
<tr>
<td width="48%" class="table">学号:<%=userNow%></td>
<td width="52%" class="table">姓名:<%=S_name%></td>
</tr>
<tr>
<td class="table">性别:<%=(Sex==null?"":Sex)%></td>
<td class="table">年级:<%=(Grade==null?"":Grade)%></td>
</tr>
<tr>
<td colspan="2" class="table">专业:<%=(Major==null?"":Major)%>
<input name="S_id" type="hidden" id="S_id" value="<%=S_id%>"> <input name="S_name" type="hidden" id="S_name" value="<%=S_name%>"></td>
</tr>
<%
s = conn.prepareStatement("select * from score where s_id=?");
s.setString(1,userNow);
ResultSet rs=s.executeQuery();
if(rs.next())
{
%>
<tr>
<td colspan="2" class="table"> 你已经参加过考试了,你的上次考试成绩为:<%=rs.getInt("score")%> </td>
</tr>
<%
}
%>
<tr>
<td colspan="2"><p align="center" class="unnamed1">警告:</p>
<p align="center" class="unnamed1">答题过程不能中断!如果您试图进行作弊或者超过答题时间,</p>
<p align="center" class="unnamed1">您将被强令在24小时后进行补考,补考时间到期前,您不能参加考试!</p>
<p align="center" class="banquan">如果您准备完毕,点按钮开始答题!</p>
<p align="center">
<input type="image" border="0" src="img/zhunbei.gif" align="准备完毕" width="97" height="38" onClick="formzhunbei.submit()" name="image">
</p></td>
</tr>
</table>
<p class="banquan"> </p>
</form>
<p> </p>
<p> </p>
</div>
<%
}
else
{
out.print(" <span class='unnamed1'>用户ID不存在或密码错误!<br><a href='login.jsp' target='_self'>返回</a></span>");
}
%>
</body>
</html>
报错是:org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 31 in the jsp file: /reading.jsp
Generated servlet error:
The method executeQuery() in the type PreparedStatement is not applicable for the arguments (PreparedStatement)
其中JAVABEAN.JAVA 读取配置文件的代码是:
//DBConnectionBean.java
//用在jsp网页里的数据库桥接bean
package examinline;
import java.util.*;
import java.sql.*;
import java.io.*;
public class DBConnectionBean{
Connection dbcon=null;
Statement stmt=null;
ResultSet result=null;
String driver="";
String url="";
String user="";
String password="";
public DBConnectionBean(){
try{
InputStream fis =getClass().getResourceAsStream("jdbcsql.properties");
Properties ps=new Properties();
ps.load(fis);
driver=ps.getProperty("driver");
url=ps.getProperty("url");
user=ps.getProperty("username");
password=ps.getProperty("password");
Class.forName(this.driver);
}
catch(Exception e){
System.out.println(e);
}
}
public void setdrivername()
{
try{
Class.forName(this.driver);
System.out.println("加载数据驱动成功!");
}catch(ClassNotFoundException e){
System.out.println("jdbc driver error");
}
}
public Connection getopenConnection(){
try{
this.dbcon=DriverManager.getConnection(this.url,this.user,this.password);
System.out.println("桥接数据库成功!");
}catch(SQLException e2){
System.out.println(e2);
}
return dbcon;
}
public ResultSet executeQuery(String query)throws SQLException{
this.stmt=dbcon.createStatement();
this.result=stmt.executeQuery(query);
return result;
}
public void executeUpdate(String query)throws SQLException{
this.stmt=dbcon.createStatement();
stmt.executeUpdate(query);
if(stmt!=null) stmt.close();
}
public String getData(int index) throws SQLException{
return result.getString(index);
}
public int getIntData(int index) throws SQLException{
return result.getInt(index);
}
public float getFltData(int index) throws SQLException{
return result.getFloat(index);
}
public boolean next() throws SQLException{
return result.next();
}
public void resetResult() throws SQLException{
this.result=null;
}
public void close() throws SQLException{
if(dbcon!=null) dbcon.close();
if(stmt!=null) stmt.close();
if(result!=null) result.close();
}
public void finalize() throws Throwable{
this.close();
}
public String replaceString(String str){
char tempArray[]=str.toCharArray();
int iCurr[]=new int[10];
int j=0;
for(int i=0;i!=tempArray.length;i++)
{
int temp=(int)tempArray[i];
if(temp==92){
iCurr[j]=i;
j++;
}
}
final int temp2=j+1;
String strArray[]=new String[temp2];
strArray[0]=str.substring(0,iCurr[0]);
strArray[temp2-1]=str.substring(iCurr[j-1]+1);
for(int m=1;m!=strArray.length-1;m++){
strArray[m]=str.substring(iCurr[m-1]+1,iCurr[m]);
}
str="";
for(int k=0;k!=strArray.length-1;k++){
str=str+strArray[k]+"%5C";
}
str=str+strArray[temp2-1];
return str;
}
}