顶了先
相信自己可以的!!! http://www.
jsp数据库连接问题
各位大侠好,我是JSP的初学者,今天我在调试jsp与SQL SERVER 2000 的连接时,只要我一连接就报错,错误内容如下:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.microsoft.jdbc.sql.server.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.connecttest_jsp._jspService(connecttest_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ClassNotFoundException: com.microsoft.jdbc.sql.server.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:148)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.connecttest_jsp._jspService(connecttest_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28
我的配置是Tomcat5.0.28+jdk1.5.6
请问这个问题怎么解决?
接第65楼
我jsp的连接代码是:
<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<%@ page import="java.sql.*,java.io.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>connecttest</title>
</head>
<body>
以下是从MS SQL Server数据库中读取的数据:<hr>
<table border=1>
<tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%!String trans(String str)
{
String result=null;
byte temp[];
try
{
temp=str.getBytes("gb2312");
result=new String(temp);
}
catch(java.io.UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
return result;
}
%>
<%
Class.forName("com.microsoft.jdbc.sql.server.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
Connection conn=java.sql.DriverManager.getConnection(url,"sa","cwx,2006");
Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery("select * from book;");
while(rst.next()){%>
<%out.println("<tr>");
out.println("<td>"+trans(rst.getString("bookid"))+"</td>");
out.println("<td>"+trans(rst.getString("bookname"))+"</td>");
out.println("<td>"+trans(rst.getString("publisher"))+"</td>");
out.println("<td>"+rst.getFloat("price")+"</td>");
out.println("</tr>");%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%//关闭连接、释放资源
rst.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>