为什么用eclipse中的webservice发布服务时和MYSQl连接时怎是加载JDBC失败?
每次测试时都是出现下面的加载驱动失败,请教大神装载 JDBC/ODBC 驱动程序失败。
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1666)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1511)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.web.MyWeb.get(MyWeb.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
源代码在下面:
package com.web;
import java.sql.*;
public class web {
private static final long serialVersionUID = 1L;
private Connection connection;
private Statement statement;
private ResultSet resultSet;
// GUI变量定义
//登陆
public String get(String name, String passwd) throws SQLException {
// Form的标题
String url = "jdbc:mysql://211.87.147.192/school";
String user = "school";
String password = "school";
// 加载驱动程序以连接数据库
try {
Class.forName("org.git.mm.mysql.Driver");
connection = DriverManager.getConnection(url, user, password);
}
// 捕获加载驱动程序异常
catch (java.lang.ClassNotFoundException e) {
System.err.println("装载 JDBC/ODBC 驱动失败");
e.printStackTrace();
System.exit(1); // terminate program
}
// 捕获连接数据库异常
catch (SQLException ex) {
System.err.println("无法连接数据库");
ex.printStackTrace();
System.exit(1); // terminate program
}
// 如果数据库连接成功,则建立GUI
// SQL语句
String test = "SELECT * FROM school_board WHERE name=" + name
+ " and passwd=" + passwd + " ";
try {
statement = connection.createStatement();
resultSet = statement.executeQuery(test);
} catch (SQLException sqlex) {
sqlex.printStackTrace();
}
if (resultSet.next()) {
String city =resultSet.getString(3);
return "YES"+city;
} else {
return "NO";
}
}
//注册
public String insert(String name, String passwd,String city) throws SQLException {
// Form的标题
String url = "jdbc:mysql://211.87.147.192:3306/school";
String user = "school";
String password = "school";
// 加载驱动程序以连接数据库
try {
Class.forName("org.git.mm.mysql.Driver");
connection = DriverManager.getConnection(url, user, password);
}
// 捕获加载驱动程序异常
catch (java.lang.ClassNotFoundException e) {
System.err.println("装载 JDBC/ODBC 驱动失败");
e.printStackTrace();
System.exit(1); // terminate program
}
// 捕获连接数据库异常
catch (SQLException ex) {
System.err.println("无法连接数据库");
ex.printStackTrace();
System.exit(1); // terminate program
}
// 如果数据库连接成功,则建立GUI
// SQL语句
Statement sql = connection.createStatement();
String sql_insert = "insert into user values('" + name + "','"
+ passwd + "','"+city+"')";
System.out.print(sql_insert);
boolean b = sql.execute(sql_insert);
if (b == true) {
return "success";
}
return "ok";
}
}
--------------------编程问答-------------------- 报的就是org.git.mm.mysql.Driver所在驱动包找不到哩
包有加到lib目录吗?看下部署目录下有没有对应驱动包。 --------------------编程问答-------------------- 我加到jre里面的lib目录了,能具体一点么?
补充:Java , Eclipse