Results 1 to 4 of 4

Thread: Could not open JDBC connection for transaction.

  1. #1
    Join Date
    Feb 2007
    Location
    Saint Louis
    Posts
    86

    Default Could not open JDBC connection for transaction.

    Having an issue getting JNDI working with Tomcat. I've configured my web.xml inside my project with this;
    Code:
    <resource-ref>
    		<description>MySql</description>
    		<res-ref-name>NestleServletDataFetcher</res-ref-name>
    		<res-type>javax.sql.DataSource</res-type>
    		<res-auth>Container</res-auth>
    	</resource-ref>
    and the Tomcat5.5.20 server.xml is configured with:
    Code:
    <Resource name="NestleServletDataFetcher"
        	      type="javax.sql.DataSource"
        	      maxActive="4"
        	      maxIdle="2"
        	      username="nestle"
        	      maxWait="5000"
        	      driverClassName="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
        	      password="nestle"
        	      url="jdbc:mysql://partnersam.talisentech.com:3306/nestle_bill_history"/>
    I'm using the mysql-connector-java-5.1.6-bin.jar and I put that in the common/lib directory of Tomcat.

    In my dataAccessContext.xml I've configured it like so;
    Code:
    <!-- Main JNDI DataSource for J2EE environments -->
    		<jee:jndi-lookup id="dataSource" jndi-name="NestleServletDataFetcher"/>
    Full Error in server log: org.springframework.transaction.CannotCreateTran
    sactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

    Am I missing a jar or is this a configuration issue?
    Andrew W. McDougall

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Your datasource configuration is wrong. the 'driverClassName' should obviously point to the JDBC driver classname NOT the classname of the DataSource.

    Here is an old blog post of mine describe somethings regarding tomcat and mysql.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2007
    Location
    Saint Louis
    Posts
    86

    Exclamation Could not open JDBC connection for transaction.

    I looked at your post and tried what you had there and now it can't create the bean for dataSource in my dataAccessContext.xml. Do I need to remove the stuff I had in the web.xml? or am I missing something? Can you please explain a little?

    Thanks.

    This is what I have now: web.xml
    Code:
    <resource-ref>
    		<description>MySql</description>
    		<res-ref-name>NestleServletDataFetcher</res-ref-name>
    		<res-type>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</res-type>
    		<res-auth>Container</res-auth>
    	</resource-ref>
    server.xml:
    Code:
    <Resource name="NestleServletDataFetcher"
        	      auth="Container"
        	      type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
        	      factory="com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory"
        	      maxActive="4"
        	      maxIdle="2"
        	      username="nestle"
        	      maxWait="5000"
        	      driverClassName="org.gjt.mm.mysql.Driver"
        	      password="nestle"
        	      explicitUrl="true"
        	      url="jdbc:mysql://partnersam.talisentech.com:3306/nestle_bill_history"/>
    Error: 2008-08-26 10:29:44,768 ERROR [org.springframework.web.context.ContextLoader] -
    Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wih name 'dataSource': Invocation of init method failed; nested exception is java.naming.NameNotFoundException: Name NestleServletDataFetcher is not bound in this Context
    Andrew W. McDougall

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Your web.xml should have a normal javax.sql.DataSource as a res-type. I would start with that.

    Try setting the 'resourece-ref' property to true in the jndi-lookup tag if the above doesn't solve it.

    Code:
    <jee:jndi-lookup id="dataSource" jndi-name="NestleServletDataFetcher" resource-ref="true"/>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •