我是 struts 的新手,正在尝试创建一个简单的 Web 应用程序。我无法连接到 derby 数据库。我的构建路径和 lib 文件夹有 derby jars。但我仍然得到“没有合适的驱动程序”发现异常。我的 Tomcat 日志显示
SEVERE: Initializing application data source testdata
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'jdbc:derby://localhost:1527/testdata;'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.setLogWriter(BasicDataSource.java:1134)
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:808)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 17 more
Jun 5, 2013 7:13:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet action as unavailable
Jun 5, 2013 7:13:01 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet action
javax.servlet.UnavailableException: Initializing application data source testdata
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:812)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Jun 5, 2013 7:33:51 PM org.apache.catalina.core.StandardWrapperValve invoke
信息:Servlet 操作当前不可用
我的 Struts_config 看起来像
<data-sources>
<data-source key="testdata" type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<set-property property="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
<set-property property="url" value="jdbc:derby://localhost:1527/testdata;"/>
</data-source>
</data-sources>
我的 Action 类获得如下连接
DataSource ds=getDataSource(request,"testdata");
Connection con=ds.getConnection();
我不知道这里出了什么问题。任何帮助是极大的赞赏。