如何解决 java.lang.ClassNotFoundException: 问题
jdbc连接mysql和sqlserver时都可以用这种方法解决问题
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at com.dao.ProjectDao.Insert(ProjectDao.java:27)
at com.controller.ProjectServlet.doPost(ProjectServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol
A
b
s
t
r
a
c
t
C
o
n
n
e
c
t
i
o
n
H
a
n
d
l
e
r
.
p
r
o
c
e
s
s
(
A
b
s
t
r
a
c
t
P
r
o
t
o
c
o
l
.
j
a
v
a
:
585
)
a
t
o
r
g
.
a
p
a
c
h
e
.
t
o
m
c
a
t
.
u
t
i
l
.
n
e
t
.
J
I
o
E
n
d
p
o
i
n
t
AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint
AbstractConnectionHandler.process(AbstractProtocol.java:585)atorg.apache.tomcat.util.net.JIoEndpointSocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor
W
o
r
k
e
r
.
r
u
n
T
a
s
k
(
T
h
r
e
a
d
P
o
o
l
E
x
e
c
u
t
o
r
.
j
a
v
a
:
895
)
a
t
j
a
v
a
.
u
t
i
l
.
c
o
n
c
u
r
r
e
n
t
.
T
h
r
e
a
d
P
o
o
l
E
x
e
c
u
t
o
r
Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor
Worker.runTask(ThreadPoolExecutor.java:895)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
做项目的时候 ,在http://localhost:8080/chapter1/projectadd.jsp 页面 插入数据的时候 出现问题,报出jdbc驱动加载不成功,当时在测试插入数据的时候 是成功添加的。
最后找到了解决方法: 将sqljdbc4.jar(数据库驱动包)复制到你项目里的WEB-INF下的lib下面即可
mysql解决的方法是:将mysql-connector-java-5.1.8-bin(mysql启动包)复制到你项目里的WEB-INF下的lib下面即可