日期:2014-05-17  浏览次数:20821 次

jsp链接数据库问题
jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>My JSP 'test_sql.jsp' starting page</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>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*"%>
<%!
 Connection con;
 Statement sql;
 ResultSet rs;
%>
<%

   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
    String url="jdbc:sqlserver://localhost:1433;DatabaseName=mis";
    con=DriverManager.getConnection(url,"sa","sa");
    sql=con.createStatement();
    String sqlexe="select * from identity_check";
    rs=sql.executeQuery(sqlexe);
    rs.next();
    out.println(rs.getString(1));
    out.println("数据库连接成功!");
%>
  </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 /test_sql.jsp at line 37

34: 
35:    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
36:     String url="jdbc:sqlserver://localhost:1433;DatabaseName=mis";
37:     con=DriverManager.getConnection(url,"sa","sa");
38:     sql=con.createStatement();
39:     String sqlexe="select * from identity_check";
40:     rs=sql.executeQuery(sqlexe);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet