Topic: 多谢各位,已解决!!!配置struts数据源(dbcp)的错误 |
Print this page |
1.多谢各位,已解决!!!配置struts数据源(dbcp)的错误 | Copy to clipboard |
Posted by: wilson751 Posted on: 2005-01-24 12:24 高手指点: 环境: win2000 tomcat oracle 问题: 用struts配置数据源,来操作oracle数据库. 当在LogonAction.java文件中,取得DataSource对象时,报错如下: 2005-1-23 21:38:05 org.apache.struts.action.ActionServlet initModuleDataSources 严重: Initializing application data source test org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'jdbc:oracle:thinlocalhost:1521:oradb' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou rce.java:780) at org.apache.commons.dbcp.BasicDataSource.setLogWriter(BasicDataSource. java:598) at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionSe rvlet.java:778) at org.apache.struts.action.ActionServlet.init(ActionServlet.java:331) at javax.servlet.GenericServlet.init(GenericServlet.java:211) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper. java:1019) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:86 2) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex t.java:3991) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4 335) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase .java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80 7) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep loyer.java:277) at org.apache.catalina.core.StandardHost.install(StandardHost.java:832) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:613 ) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:431 ) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:964) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java :349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl eSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478 ) at org.apache.catalina.core.StandardService.start(StandardService.java:4 76) at org.apache.catalina.core.StandardServer.start(StandardServer.java:229 8) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422) Caused by: java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou rce.java:773) ... 31 more 配置步骤: tomcat5/common/lib/下,添加了如下个jar包: commons-dbcp-1.2.jar struts-legacy.jar commons-pool-1.2.jar classes12.jar 下面是struts-config.xml和LogonAction.java, ---------struts-config.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <!-- ======== Oracle DataSource Definitions ============================ --> <data-sources> <data-source key="test" type="org.apache.commons.dbcp.BasicDataSource" > <set-property property="autoCommit" value="false"/> <set-property property="description" value="Database for equipment of System"/> <set-property property="driverClass" value="oracle.jdbc.driver.OracleDriver"/> <set-property property="maxCount" value="10"/> <set-property property="minCount" value="1"/> <set-property property="url" value="jdbc:oracle:thinlocalhost:1521:oradb"/> <set-property property="user" value="testsystem"/> <set-property property="password" value="testsystem"/> </data-source> </data-sources> <!-- ========== Action Mapping Definitions ============================== --> <action-mappings> <action path = "/LogonCheck" parameter = "logon" type = "logon.LogonAction" name = "LogonForm" scope = "request" validate = "false" input = "/logon.jsp" > <forward name="testLogon" path="/main.jsp" /> <forward name="failure" path="/failure.jsp" /> </action> <action path = "/UserManage" type = "user.UserManageAction" name = "UserManageForm" scope = "request" validate = "false" input = "/addUser.do" > </action> </action-mappings> <!-- ========== Message Resources Definitions =========================== --> <message-resources parameter="resourcebundles.application"/> </struts-config> ------------------LogonAction.java package logon; import java.sql.*; import javax.sql.*; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.util.MessageResources; import org.apache.commons.beanutils.BeanUtils; public final class LogonAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DataSource dataSource = null; Connection cnn = null; try { dataSource = getDataSource(request,"test"); cnn = dataSource.getConnection(); } catch (SQLException e) { getServlet().log("处理数据库连接", e); } finally { // 在finally块里包含这些代码 // 用以保证连接最后会被关闭 try { cnn.close(); } catch (SQLException e) { getServlet().log("关闭数据库连接", e); } } return mapping.findForward("testLogon"); } } |
2.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: glistar Posted on: 2005-01-24 16:14 没有添加 Oracle JDBC 驱动 |
3.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2005-01-24 19:41 classes12.jar 不是oracle的驱动吗 |
4.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: glistar Posted on: 2005-01-25 08:40 把 <data-source key="test" type="org.apache.commons.dbcp.BasicDataSource" > 改成 <data-source type="org.apache.commons.dbcp.BasicDataSource" > 看看 |
5.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2005-01-25 22:49 我又重新试了一下, 将LogonAction.java的execute()方法中调用 数据源的 dataSource = getDataSource(request,"test"); cnn = dataSource.getConnection(); 去掉,也就是,只配置了struts-config.xml文件, 结果,tomcat5启动时报错: 2005-1-25 19:41:45 org.apache.struts.action.ActionServlet initModuleDataSources 严重: Initializing application data source org.apache.struts.action.DATA_SOURCE org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'jdbc:oracle:thinlocalhost:1521:oradb', cause: java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou rce.java:743) at org.apache.commons.dbcp.BasicDataSource.setLogWriter(BasicDataSource. java:576) at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionSe rvlet.java:778) at org.apache.struts.action.ActionServlet.init(ActionServlet.java:331) at javax.servlet.GenericServlet.init(GenericServlet.java:211) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper. java:1019) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:86 2) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex t.java:3991) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4 335) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase .java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80 7) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep loyer.java:277) at org.apache.catalina.core.StandardHost.install(StandardHost.java:832) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:613 ) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:431 ) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:964) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java :349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl eSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478 ) at org.apache.catalina.core.StandardService.start(StandardService.java:4 76) at org.apache.catalina.core.StandardServer.start(StandardServer.java:229 8) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422) |
6.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: glistar Posted on: 2005-01-26 09:27 dataSource = getDataSource(request,"test"); 改成 dataSource = getDataSource(request); 因为配置文件中的key去掉了呀 |
7.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2005-01-26 10:32 这个当然去掉了 |
8.Re:高手sos!!!配置struts数据源(dbcp)的错误 [Re: wilson751] | Copy to clipboard |
Posted by: wilson751 Posted on: 2005-01-26 10:36 现在是,不在 LogonAction.java中访问数据源, 只是配置了struts-config.xml, 一启动tomcat5,控制台就报错: 如上所示 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |