sql server 2008 jdbc 驱动连接出问题
sql server 2008 jdbc驱动包连接了,但是还是跳出这样的问题,为什么啊?
<%@ page language="java" contentType="text/html; charset=gbk"
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=gbk">
<title>Insert title here</title>
</head>
<body>
<%
//接受数据
String u=request.getParameter("username");
String p=request.getParameter("password");
//到数据库验证
//加载驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//数据库连接对象
Connection ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Login","sa","19930821");
//sql语句对象
Statement stmt=ct.createStatement();
//查询
ResultSet rs=stmt.executeQuery("selest password from User where userName='"+u+"'");
//根据结果判断
if(rs.next())
{
//如果能进到这里面,说明用户名存在
if(rs.getString(1).equals(p))
{
//一定合法
response.sendRedirect("welcome.jsp?user="+u);
}
else
{
//密码错误
response.sendRedirect("login.jsp?error=1");
}
}
else
{
//用户名不存在
response.sendRedirect("login.jsp?error=2");
}
%>
</body>
</html>
---------------------------------------------
HTTP Status 500 - javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
--------------------------------------------
type Exception report
message javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.logincl_jsp._jspService(logincl_jsp.java:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
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.logincl_jsp._jspService(logincl_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.
sql?server?2008 exception
[解决办法]
sql server 2008的驱动类加载错了
是Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
不是
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
数据库的连接应该是
Connection ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Login","sa","19930821");