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

jsp链接sql server总出HTTP Status 500 -异常

2013-09-11 
jsp链接sql server总出HTTP Status 500 -错误代码如下:%@pagecontentType text/htmlcharsetgb2312 %

jsp链接sql server总出HTTP Status 500 -错误
代码如下:
<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>
<html>
<body>
<%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();

String   url   = "jdbc:microft:sqldriver//loaclhost:1433;DatabaseName=PUBS ";  
Connection   conn=   DriverManager.getConnection(url, "guest ", " ");
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String   sql= "select   *   from   authors ";
ResultSet   rs=stmt.executeQuery(sql);
while(rs.next())   {%>
您的第一个字段内容为: <%=rs.getString(1)%>
您的第二个字段内容为: <%=rs.getString(2)%>
<%}%>
<%out.print( "数据库操作成功,恭喜你 ");%>
<%rs.close();
stmt.close();
conn.close();
%>
</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:   com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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)

root   cause

javax.servlet.ServletException:   com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
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)

root   cause

java.lang.ClassNotFoundException:   com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:127)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
java.lang.ClassLoader.loadClassInternal(Unknown   Source)
java.lang.Class.forName0(Native   Method)
java.lang.Class.forName(Unknown   Source)
org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:50)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
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)



note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.5.15   logs.

[解决办法]
代码如下:
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<html>
<body>
<%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();

String url = "jdbc:microft:sqldriver//loaclhost:1433;DatabaseName=PUBS ";
Connection conn= DriverManager.getConnection(url, "guest ", " ");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "select * from authors ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为: <%=rs.getString(1)%>
您的第二个字段内容为: <%=rs.getString(2)%>
<%}%>
<%out.print( "数据库操作成功,恭喜你 ");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

--------------------------------------
你的程序写错了,url:jdbc:microsoft:.............检查一下程序
[解决办法]
sql驱动没赔好,连接数据库失效
[解决办法]
你的数据库是sql server 2000还是2005?

[解决办法]
1,到
http://msdn2.microsoft.com/zh-cn/library/ms378749.aspx
下载最好用的新版本的驱动
2,将解压的jar放在你站点下的web-INF\lib下


[解决办法]
String url = "jdbc:microft:sqldriver://loaclhost:1433;DatabaseName=PUBS ";
**** *

1、sqlserver不是sqldriver!!!
2、冒号掉了!

细心点, 呵呵
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行