JSP连接SqlServer2005问题,提示找不到适当的JDBC驱动

时间:2022-11-11 04:41:50
我刚接触JSP,想配置出JSP连接SqlServer2005的开发环境,但总是报错,提示找不到适当的JDBC驱动,不知道是什么原因,请哪位大哥帮忙指点一下,谢谢了

我的操作环境是:tomcat5.5.28 jdk1.6.0_10 SqlServer2005

系统变量:
Classpath
c:\temp\sqljdbc.jar;C:\temp\sqljdbc4.jar;C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar;C:\Program Files\Java\jre6\lib\rt.jar;

Path
C:\Program Files\Java\jdk1.6.0_10\bin\

已将JDBC驱动(sqljdbc.jar和sqljdbc4.jar)拷贝到tomcat5.5\common\lib和tomcat5.5\webapps\root\web-inf\lib目录下,重新启动tomcat

test.jsp代码如下:

<%@ page language="java" contentType="text/html;charset=gb2312"%> 
<%@ page import="java.sql.*"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>Insert title here</title>
<body> 
<%
//变量声明
Connection conn;
ResultSet rs;
Statement st;
//变量声明结束
 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//jdbc驱动
//数据库连接字符串
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev"; 
conn= DriverManager.getConnection(url,"sa",""); //设置conn
//设置st
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
   rs=st.executeQuery("select * from book");//sql查询语句 
 
%> 
</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: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

javax.servlet.ServletException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


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

14 个解决方案

#1


jdbc 不懂 帮顶

#2


网上找一下!

#3


引用 1 楼 billpu 的回复:
jdbc 不懂 帮顶
.

#4


//变量声明结束 
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//jdbc驱动 

这里写错了!

应该这样Class.forName("com.microsoft.sqlserver.SQLServerDriver");//

#5


该回复于2009-09-22 15:58:59被版主删除

#6


4楼的朋友,我按照你写的修改过了,可是还是报错

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: /test1.jsp:14

11: ResultSet rs;
12: Statement st;
13: //变量声明结束
14:  Class.forName("com.microsoft.sqlserver.SQLServerDriver");//jdbc驱动
15: //数据库连接字符串
16: String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev"; 
17: conn= DriverManager.getConnection(url,"sa",""); //设置conn


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

javax.servlet.ServletException: com.microsoft.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

java.lang.ClassNotFoundException: com.microsoft.sqlserver.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:56)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

#7


请问。你是否把
msbase.jar
mssqlserver.jar
msutil.jar
这三个包导入程序了?

#8


刚写错了。。不是那三个包。
SQL2005就是一个驱动包需要导入
你可以去
http://download.csdn.net/source/813745 去这下载下

#9


已将JDBC驱动(sqljdbc.jar和sqljdbc4.jar)拷贝到tomcat5.5\common\lib和tomcat5.5\webapps\root\web-inf\lib目录下,重新启动tomcat 



你这两个路径都不对
应该添加到
tomcat5.5\webapps\你的项目\web-inf\lib  下面

#10


你放到common 和 root下面有啥用?

#11


“应该添加到 tomcat5.5\webapps\你的项目\web-inf\lib  下面”
这下面我也添加过了,可是还是报(No suitable driver found for jdbc)这个错,哎~~~~~

#12


应该添加到 tomcat5.5\webapps\你的项目\web-inf\lib  下面就可以啦!!

#13


最好还是在项目上右键--classpath上 选择外部jar包 

#14


这些的前提下是你的jar包必须正确
http://download.csdn.net/source/871050

#1


jdbc 不懂 帮顶

#2


网上找一下!

#3


引用 1 楼 billpu 的回复:
jdbc 不懂 帮顶
.

#4


//变量声明结束 
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//jdbc驱动 

这里写错了!

应该这样Class.forName("com.microsoft.sqlserver.SQLServerDriver");//

#5


该回复于2009-09-22 15:58:59被版主删除

#6


4楼的朋友,我按照你写的修改过了,可是还是报错

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: /test1.jsp:14

11: ResultSet rs;
12: Statement st;
13: //变量声明结束
14:  Class.forName("com.microsoft.sqlserver.SQLServerDriver");//jdbc驱动
15: //数据库连接字符串
16: String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev"; 
17: conn= DriverManager.getConnection(url,"sa",""); //设置conn


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

javax.servlet.ServletException: com.microsoft.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause 

java.lang.ClassNotFoundException: com.microsoft.sqlserver.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:56)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

#7


请问。你是否把
msbase.jar
mssqlserver.jar
msutil.jar
这三个包导入程序了?

#8


刚写错了。。不是那三个包。
SQL2005就是一个驱动包需要导入
你可以去
http://download.csdn.net/source/813745 去这下载下

#9


已将JDBC驱动(sqljdbc.jar和sqljdbc4.jar)拷贝到tomcat5.5\common\lib和tomcat5.5\webapps\root\web-inf\lib目录下,重新启动tomcat 



你这两个路径都不对
应该添加到
tomcat5.5\webapps\你的项目\web-inf\lib  下面

#10


你放到common 和 root下面有啥用?

#11


“应该添加到 tomcat5.5\webapps\你的项目\web-inf\lib  下面”
这下面我也添加过了,可是还是报(No suitable driver found for jdbc)这个错,哎~~~~~

#12


应该添加到 tomcat5.5\webapps\你的项目\web-inf\lib  下面就可以啦!!

#13


最好还是在项目上右键--classpath上 选择外部jar包 

#14


这些的前提下是你的jar包必须正确
http://download.csdn.net/source/871050