核心代码部分:
String databaseName = "RbMwPrdlElXBMixvJNjX";
String host = "sqld.duapp.com";
String port = "4050";
String username = "gIPwyeDhKVykpPTa4i2w83Q6";// API_KEY
String password = "GfbVVaYhVpgwN3FPEVsxKj0XuRhfzW3C";// SCRECT_KEY
// 本地数据库连接
// String databaseName = "CilentInfo";
// String host = "localhost";
// String port = "3306";
// String username = "root";
// String password = "awd4294967299#";
System.out.println("Done_0");
String driverName = "com.mysql.jdbc.Driver";
String dbUrl = "jdbc:mysql://";
String serverName = host + ":" + port + "/";
String connName = dbUrl + serverName + databaseName;
// + "?autoReconnectForPools=true" +
// "&connectTimeout=10000";
Class.forName(driverName);
System.out.println("Done_1");
setTestLog(getTestLog() + "Done_ClassForName");
this.testLog+="Done_ClassForName";
conn = DriverManager.getConnection(connName, username, password);
System.out.println("Done_2");
setTestLog(getTestLog() + "Done_getConnection");
this.testLog+="Done_getConnection";
stmt = conn.createStatement();
setTestLog(getTestLog() + "Done_CreatStmt");
this.testLog+="Done_CreatStmt";
System.out.println("Done_3");
sql = InsertData(user);
this.testLog+="Done_InsertData";
System.out.println("Done_4");
stmt.execute(sql);
String rs_sql = "insert into User(Name,PhoneNum,Address,ExpressCmpy,Size,getTime,price,remarks,status) ";
rs_sql += "values('" + user.getName() + "','" + user.getPhoneNum()
+ "','" + user.getAddress() + "','" + user.getExpressCmpy()
+ "'," + user.getSize() + "," + user.getGetTime() + ","
+ user.getPrice() + ",'" + user.getRemarks() + "',"
+ user.getStatus() + ")";
return rs_sql;
1、需要在百度云服务器运行才能访问云服务器(我用GIT上传代码了,但未能解决问题)
找到问题所在了!!!!
原因:
at java.lang.Thread.run(Thread.java:724)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at org.apache.jsp.getUserForm_jsp._jspService(getUserForm_jsp.java:129)
at com.bnuz66.User.upLoad2Sql(User.java:20)
at com.bnuz66.UpLoadService.<init>(UpLoadService.java:41)
at java.lang.Class.forName(Class.java:190)
at java.lang.Class.forName0(Native Method)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
解决步骤
1、检查J2ee工程文件中是否导入了额外工程包
右键工程文件->Build path-> configure build path ->Java Build path->Library->Add External JARs
选择自己的mysql-connector-java.jar包(注意,百度云数据库需要5.1.22版本以上)
2、检查Tomcat - lib文件夹下是否有上面的jar包
3、(重点!!我就错这里!!)检查自己j2ee工程文件夹下webContent->WEB-INF-lib文件夹下是否有jar包!!!!!!!!!!!
总结:一开始用百度云都不知道在哪里看的LOG日志,后面在应用首页里面的日志中的stderr.log日志中可以看到自己程序的问题所在,希望我的日志能够帮你减少时间