File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Problems with MYSQL JDBC connection in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problems with MYSQL JDBC connection in Tomcat " Watch "Problems with MYSQL JDBC connection in Tomcat " New topic
Author

Problems with MYSQL JDBC connection in Tomcat

Steve Popoola
Greenhorn

Joined: May 14, 2009
Posts: 1
Hello everyone,

I am new to Java and have been battling with this problem for over a week now.

I wrote a web application which was deployed in Tomcat running on Windows XP and it ran successfully. However, deployment to my linux server and also to my Mac OS has been a pain. I copied the exact codes in my Windows app and rebuilt in Netbeans before deploying to my Tomcat on linux. I also copied over my context.xml and web.xml. I am using connection pooling so that once Tomcat starts, a connection is made. However in my linux server, I keep getting the following errors;
May 11, 2009 1:18:21 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
javax.naming.NamingException: Cannot create resource instance


I am using Tomcat 6.0.18 and MySQL 5.0. I copied the mysql connector to $CATALINA/lib.

I will appreciate help on sorting this problem out.

My context.xml:
<?xml version="1.0" encoding="UTF-8"?>

<Context path="/WebApplication1" docbase="WebApplication1" debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/DB" auth="Container" type="javax.sql.Datasource" maxActive="10" maxIdle="4"
username="javatutor"
password="javatutor"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/java_training?autoReconnect=true">
</Resource>
</Context>

My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<description>ServletContextListener</description>
<listener-class>com.fidelitybank.ServletListener</listener-class>
</listener>
<servlet>
<servlet-name>AccountServlet</servlet-name>
<servlet-class>com.fidelitybank.AccountServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AccountServlet</servlet-name>
<url-pattern>/AccountServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>for my jdbc</description>
<res-ref-name>jdbc/DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

My catalina.out:

java.lang.Exception: Couldn't open connection to database: Cannot create resource instance
at com.fidelitybank.DBAO.<init>(DBAO.java:53)
at com.fidelitybank.ServletListener.contextInitialized(ServletListener.java:24)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
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:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Couldn't create database bean: Couldn't open connection to database: Cannot create resource instance
May 11, 2009 2:01:49 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 11, 2009 2:01:49 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 11, 2009 2:01:49 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/25 config=null
May 11, 2009 2:01:49 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 881 ms
java.lang.NullPointerException
at com.fidelitybank.AccountServlet.init(AccountServlet.java:33)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:808)
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:128)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:613)
java.lang.NullPointerException
at com.fidelitybank.AccountServlet.processRequest(AccountServlet.java:52)
at com.fidelitybank.AccountServlet.doPost(AccountServlet.java:103)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:613)
May 13, 2009 7:07:47 PM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
May 13, 2009 7:07:49 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
May 13, 2009 7:07:51 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080




I can do all things through Christ!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with MYSQL JDBC connection in Tomcat
 
Similar Threads
Hi Gregg!
Tomcat Error after moving from struts 1.1 to struts 1.3.10
unabale to deploy application. error in file location and tomcat
Getting error----NoContextLoaderListener registered
JAX-WS in web application.