关于jsp连接MSsql200数据库的问题
代码如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc.microsoft.sqlserver://localhost:1433;DatabaseName=student";
String user = "sa";
String password = "";
Connection conn = java.sql.DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
String str = "select * from student;";
ResultSet reset = stmt.executeQuery(str);
out.println("<table border='1' bgcolor='cyan'>");
out.println("<tr>");
out.println("<th width='50'>" + "学号");
out.println("<th width='50'>" + "姓名");
out.println("<th width='100'>" + "数学成绩");
out.println("<th width='100'>" + "英语成绩");
out.println("<th width='100'>" + "物理成绩");
out.println("</tr>");
while (reset.next())
{
out.println("<tr>");
out.println("<td>" + reset.getString(1) + "</td>");
out.println("<td>" + reset.getString(2) + "</td>");
out.println("<td>" + reset.getString(3) + "</td>");
out.println("<td>" + reset.getString(4) + "</td>");
out.println("<td>" + reset.getString(5) + "</td>");
out.println("</tr>");
}
out.println("</table>");
conn.close();
%>
</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: Exception in JSP: /ch001.jsp:11
8: String url = "jdbc.microsoft.sqlserver://localhost:1433;DatabaseName=student";
9: String user = "sa";
10: String password = "";
11: Connection conn = java.sql.DriverManager.getConnection(url,user,password);
12: Statement stmt = conn.createStatement();
13: String str = "select * from student;";
14: ResultSet reset = stmt.executeQuery(str);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: No suitable driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.ch001_jsp._jspService(ch001_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getConnection(DriverManager.java:545)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.ch001_jsp._jspService(ch001_jsp.java:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
不知道怎么回事,请高手指教!!!