首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

大家帮小弟我看看数据库连接的小疑点,多谢

2013-09-11 
大家帮我看看数据库连接的小问题,谢谢.下面是个连接数据库的小程序,用SQL2000建立数据库Vote,然后建两个表

大家帮我看看数据库连接的小问题,谢谢.
下面是个连接数据库的小程序,用SQL2000建立数据库Vote,然后建两个表voter和result.下面的javaBean文件名(conn.java)package vote;
import java.sql.*;
public class conn{
  String DBDdriver="sun.jdbc.odbc.JdbcOdbcDriver";

  String rsDBDdriver="jdbc:odbc:vote";

  Connection con=null;
  ResultSet rs=null;

  public conn(){
  try{
  Class.forName(DBDdriver);
  }catch(java.lang.ClassNotFoundException e){
  System.err.println(e.getMessage());
  }
  }

  public ResultSet executeQuery(String sql){
  rs=null;
  try{
  con=DriverManager.getConnection(rsDBDdriver); 
  Statement stmt=con.createStatement();
  rs=stmt.executeQuery(sql);
  }catch(SQLException ex){
  System.err.println(ex.getMessage());
  }  

  return rs;
}
}


下面是显示表格的jsp文件(show.jsp)
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="voteBean" class="vote.conn" scope="page"/>
<html>
<head>
<title>SQL SHOW!</title>
<meta http-equiv="Content-Type" content="text/http;charset=gb-2312-80">
<meta content="blueriver" name="Author">
<meta http-equiv="refresh" content="10;URl=show.jsp">
</head>
<body bgcolor="red">
 <div align="center">
  <h1>当前统计票数</h1>
  <table border="1" width="60%">
  <tr>
  <td width="51%">候选公司名</td>
  <td width="49%">当前票数</td>
  </tr>
  <%
  ResultSet rst=voteBean.executeQuery("select * from result");
  String companyName;
  int voteNum;
  while(rst.next()){
  companyName=rst.getString("candidate");
  voteNum=rst.getInt("vote_num");
  %> 
  <tr>
  <td width="51%"><%=companyName%></td>
  <td width="49%"><%=voteNum%></td> 
  </tr>
  <%
  }
  rst.close(); 
  %> 
 </table>
 </div>
 <div align="center">
  <h1>投票人的详细资料</h1>
  <table border="1" width="100%">
  <tr>
  <td>投票的公司</td>
  <td>投票人姓名</td>
  <td>投票人所在公司</td>
  <td>投票人所在国家</td>
  <td>投票人的IP地址</td>
  <td>投票时间</td>
  </tr>
  <%
  ResultSet RS_vote;
  RS_vote=voteBean.executeQuery("select * from voter");
  String candidate1,name,company1,country,address;
  java.util.Date time;
  while(RS_vote.next()){
  candidate1=RS_vote.getString("candidate");
  name=RS_vote.getString("voter_name");
  company1=RS_vote.getString("voter_company");
  country=RS_vote.getString("voter_country");  
  address=RS_vote.getString("ip_address");
  time=RS_vote.getStrig("voter_time");
  %>
  <tr>
  <td><%=candidate1%></td>
  <td><%=name%></td>
  <td><%=company1></td>


  <td><%=country></td>
  <td><%=address></td>
  <td><%=time></td>
  </tr>
 <%
  }
  RS_vote.close();
 %>  
</table>
  </div>
</body>
</html>



编译的时候出现的错误:
type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on tokens, Expression expected instead

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", delete this token

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on tokens, Expression expected instead

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", delete this token

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on tokens, Expression expected instead

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", delete this token

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens

An error occurred at line: 63 in the jsp file: /show.jsp
Generated servlet error:
Syntax error on token ";", delete this token

Generated servlet error:
Syntax error, insert "}" to complete Block


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



[解决办法]
63行 <td> <%=company1> </td> 
<td> <%=country> </td> 
<td> <%=address> </td> 
<td> <%=time> </td> 
 
修改
<td> <%=company1%> </td> 
<td> <%=country%> </td> 
<td> <%=address%> </td> 
<td> <%=time%> </td> 

这样修改以后在试试
[解决办法]
<td> <%=name%> </td> 
<td> <%=company1> </td> 
<td> <%=country> </td> 


<td> <%=address> </td> 
<td> <%=time> </td> 

[解决办法]
<td> <%=company1%> </td>
<td> <%=country%> </td>
<td> <%=address%> </td>
<td> <%=time%> </td> 
另外,定义字符串是赋初值:
String company1=null,......;
[解决办法]
<tr> 
<td> <%=candidate1%> </td> 
<td> <%=name%> </td> 
<td> <%=company1> </td> 
<td> <%=country> </td> 
<td> <%=address> </td> 
<td> <%=time> </td> 
</tr> 

[解决办法]
<td> <%=company1> </td> 
<td> <%=country> </td> 
<td> <%=address> </td> 
<td> <%=time> </td> 

--->>>
<td> <%=company1%> </td> 
<td> <%=country%> </td> 
<td> <%=address%> </td> 
<td> <%=time%> </td> 


我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行