当前位置: 代码迷 >> Java Web开发 >> 急jsp连接SQL Server2008失败,求大神见见
  详细解决方案

急jsp连接SQL Server2008失败,求大神见见

热度:2580   发布时间:2016-04-10 23:37:40.0
急!,jsp连接SQL Server2008失败,求大神看看
以下是我的代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>通过JDBC驱动访问SQLSever 2008</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
    <center>
      <br/><br/><br/>
      <h2>使用JDBC驱动访问 SQL Server 2008数据库</h2>
      <hr/>
      <table border=2 bgcolor="ccceee" align="center">
           <tr>
              <th>学号</th>
              <th>姓名</th>
              <th>性别</th>
              <th>年龄</th>
              <th>体重</th>
           </tr>
        <%
           Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
           String url = "jdbc:sqlserver://localhost:1433;databasename=student";
           String user = "sa";
           String password="root";
           Connection conn=DriverManager.getConnection(url,user,password);
           Statement stmt = conn.createStatement();
           String sql = "select * from info";
           ResultSet rs = stmt.executeQuery(sql);
           while(rs.next()){
         %>
         <tr>
           <td><%=rs.getString("studentNumber") %></td>
           <td><%=rs.getString("studentName") %></td>
           <td><%=rs.getString("studentSex") %></td>
           <td><%=rs.getString("studentAge") %></td>
           <td><%=rs.getString("studentWeight") %></td>
         </tr>
         <%
         }
         rs.close();
         stmt.close();
         conn.close();
          %>
      </table>
      <hr/>
    </center>
  </body>
</html>
----------------------------------------------------------------------------
报错内容:
HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /accessSQLServer2008.jsp at line 40

37:               <th>浣撻噸</th>
38:            </tr>
39:         <%
40:            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  相关解决方案