jsp连接sqlserver2008怎么都连不上!急!!!

木子佳佳 企业信息开发运维  2015-07-12 01:31:58
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<center>
<table border="1" cellpadding="5" cellspacing="0">
<tr>
<td>id编号</td>
<td>姓名</td>
<td>年龄</td>
<td>性别</td>
<td>email</td>
<td>学历</td>
<td>备注</td>
</tr>
<%

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=gwc";
String user="sa";
String password="111111";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from User_Info";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
%>
<tr>
<td><%=rs.getString("id")%></td>
<td><%=rs.getString("userName")%></td>
<td><%=rs.getString("age")%></td>
<td><%=rs.getString("email")%></td>
<td><%=rs.getString("gender")%></td>
<td><%=rs.getString("education")%></td>
<td><%=rs.getString("resume")%></td>
</tr>
<%
}
rs.close();
stmt.close();
conn.close();

%>
</table>
</center>
</body>
</html>


错误提示:
HTTP Status 500 - An exception occurred processing JSP page /Check.jsp at line 24


type Exception report

message An exception occurred processing JSP page /Check.jsp at line 24

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 /Check.jsp at line 24

21: </tr>
22: <%
23:
24: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
25: String url="jdbc:sqlserver://localhost:1433;databasename=gwc";
26: String user="sa";
27: String password="111111";


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.Check_jsp._jspService(Check_jsp.java:142)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.Check_jsp._jspService(Check_jsp.java:85)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



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


Apache Tomcat/7.0.59
...全文
224 8 点赞 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
木子佳佳 2015-07-16
还是不行,我也不知道怎么回事了,谢谢你耐心的回答!
  • 打赏
  • 举报
回复
qqw6789567 2015-07-13
引用 3 楼 strawberryjiajia 的回复:
数据库驱动包怎么加,是java.sql.*吗,我加过了
数据库驱动包就和你导入的包差不多啊<%@ page import="你的数据库驱动包" %> 你在爱JSP里写的build只是你导入项目了,但是JSP里还没有包,所以必须<%@ page import="com.microsoft.jdbc.sqlserver.SQLServerDriver" %> 这个不知道对不对反正就这样,我这个是2000的!
  • 打赏
  • 举报
回复
qqw6789567 2015-07-13
引用 2 楼 qiheia2 的回复:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*" %> 你的jsp页面,没有导入数据库驱动包。 在头部加入<%@ page import="你的数据库驱动包" %>
这个头部加了吗????没导入包吧,在头部加入<%@ page import="你的数据库驱动包
  • 打赏
  • 举报
回复
木子佳佳 2015-07-12
这个也build过了
  • 打赏
  • 举报
回复
qiheia2 2015-07-12
将sqljdbc4.jar复制到lib文件夹中。对sqljdbc4点右键,Build Path-->Add to Build Path
  • 打赏
  • 举报
回复
木子佳佳 2015-07-12
数据库驱动包怎么加,是java.sql.*吗,我加过了
  • 打赏
  • 举报
回复
qiheia2 2015-07-12
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*" %> 你的jsp页面,没有导入数据库驱动包。 在头部加入<%@ page import="你的数据库驱动包" %>
  • 打赏
  • 举报
回复
木子佳佳 2015-07-12
sqljdbc4.jar已经在eclipse中build path了,数据库端口也是1433没错,用odbc源连接可以,用驱动就是不行,我也是醉了,崩溃边缘......
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-07-12 01:31
社区公告
暂无公告