Spring 2.5 MVC:无法获得JDBC连接;嵌套异常是java.sql.SQLException:url不能为null

时间:2015-01-08 20:28:53

标签: spring netbeans glassfish

我正在尝试一个Spring MVC 2.5程序,该程序使用JDBCTemplate帮助程序类将记录插入到Derby表中。我正在使用Netbeans IDE 6.5.1并使用GlassFish Server。

但我得到了这个例外:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
   nested exception is java.sql.SQLException: The url cannot be null.

我已经确定了以下内容:

  • 已将Derby.jar,DerbyClient.jar添加到Web应用程序的“libraries”文件夹中。
  • 尝试使用Spring JDBCTemplate的Java应用程序,使用DerbyClient.jar将记录插入到Derby表中,这个程序运行得很漂亮。

我也尝试过在本网站上找到的其他一些建议,如:

  • 将DerbyClient.jar和Derby.jar添加到Glassfish的lib文件夹中。
  • 确保这些jar文件在类路径中可用。
你可以告诉我哪里可能错了吗?

我的属性文件:datasrc.properties

driverClassName=org.apache.derby.jdbc.ClientDriver
url=jdbc:derby://localhost:1527/sample
username=APP
password=APP

我的 dataSource bean条目:

<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${driverClassName}"/>
    <property name="url" value="${url}"/>
    <property name="username" value="${username}"/>
    <property name="password" value="${password}"/>
</bean>

我的名为MyDAO的类有一个名为 dataSource 的属性,它将被注入 dataSource bean,如下所示:

<bean id="mydao" class="MyDAO">
    <property name="dataSource" ref="dataSource"/>
</bean>

完整堆栈跟踪:

    SEVERE: ApplicationDispatcher[/SpringMVCIceCream2] PWC1231: Servlet.service() for servlet    dispatcher threw exception
java.sql.SQLException: The url cannot be null
        at java.sql.DriverManager.getConnection(DriverManager.java:554)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:283)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:271)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:255)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:236)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:357)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:404)
        at MyDAO.create(MyDAO.java:66)
        at IcecreamController1.onSubmit(IcecreamController1.java:30)
        at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:409)
        at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:381)
        at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
        at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
        at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:885)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:732)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:554)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:485)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:377)
        at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:783)
        at org.apache.jsp.index_jsp._jspService(index_jsp.java from :53)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:366)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
        at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
        at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
        at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
        at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
SEVERE: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.sql.SQLException: The url cannot be null
        at java.sql.DriverManager.getConnection(DriverManager.java:554)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:283)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:271)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:255)
        at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:236)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:357)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:404)
        at MyDAO.create(MyDAO.java:66)
        at IcecreamController1.onSubmit(IcecreamController1.java:30)
        at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:409)
        at org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:381)
        at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
        at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
        at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:885)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:732)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:554)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:485)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:377)
        at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:783)
        at org.apache.jsp.index_jsp._jspService(index_jsp.java from :53)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:366)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
        at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
        at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
        at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
        at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)

0 个答案:

没有答案