unknown
unknown

Reputation: 689

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

I am working on a web based project using spring ,hybernate +jpa .I am trying to configure JTA Transactions with Atomkios my backend is mySql. I am not able to setup the application to work with mySql. my web server is tomcat 5.5.I am trying to cal jndi configured datasource .. here my code is

persistence.xml:

  <persistence-unit name="exhub" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/exampleWeb</jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
   <class>com.evolvus.common.model.Talogin</class>
   <class>com.evolvus.common.model.TaUser</class>  
            ----------------- 
            -----------------  
           <properties>
            <property name="hibernate.transaction.manager_lookup_class" 
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
            </ properties>     
 </persistence-unit>
</persistence>

orm.xml:

<description>Evolvus Solutions</description> 
<package>com.evolvus.common.model</package>


 <entity class="com.evolvus.common.model.TaUser" name="TaUser">
  <table name="ta_user" />
  <attributes>
   <id name="userId">
   <column name="USER_ID"/>
    <generated-value strategy="TABLE" />
   </id>
   <basic name="userName">
    <column name="USER_NAME" length="50" />
   </basic>

  </attributes>
 </entity>
  ---------------
  --------------
  ---------------

</entity-mappings>

config.xml:

 <beans: bean id="sessionFactory"   
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <beans: property name="useTransactionAwareDataSource"
   value="true" /> 
  <beans: property name="hibernateProperties">
   <beans: props>
    <beans: prop key="hibernate.dialect">${database.target}</beans:prop>
    <beans: prop key="hibernate.connection.isolation">3</beans:prop>
    <beans: prop key="hibernate.current_session_context_class">jta</beans:prop>
    <beans: prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory
    </beans: prop>
    <beans: prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
    </beans: prop>
    <beans: prop key="hibernate.connection.release_mode">on_close</beans: prop>
    <beans: prop key="hibernate.show_sql">false</beans: prop>
   </beans: props>
  </beans: property>
 </beans: bean>

 <beans: bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
  <beans: property name="entityManagerFactory">
   <beans: ref bean="entityManagerFactory" />
  </beans: property>
 </beans: bean>
 <beans: bean id="entityManagerFactory"
  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <beans: property name="persistenceUnitName" value="payhub" />
  <beans: property name="jpaVendorAdapter">
   <beans:bean
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <beans: property name="generateDdl" value="false" />
    <beans: property name="showSql" value="true" />
    <beans: property name="databasePlatform" value="${database.target}" />
   </beans: bean>
  </beans: property>
  <beans: property name="persistenceXmlLocation">
   <beans: value>classpath:META-INF/persistence.xml</beans:value>
  </beans: property>
 </beans: bean>
</beans: beans>

and i configured jndi in tomcat 5.5

Apache Software Foundation\Tomcat 5.5\conf.xml:

 <Resource
      name="jdbc/exampleWeb"
      type="javax.sql.DataSource"
      maxActive="4"
      maxIdle="2"
      username="root"
      maxWait="5000"
      validationQuery="SELECT=1"
      driverClassName="com.mysql.jdbc.Driver"
      password="roopt"  
      url="jdbc\:mysql\://localhost\:3306/welcomeHub"/> 

 and my application\web.xml 

 <resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/exampleWeb</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> 

My server is staring fine but when i trying to access db data i am getting the following error in my web browser

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)

Help me

Upvotes: 0

Views: 12958

Answers (3)

Milind V. Acharya
Milind V. Acharya

Reputation: 411

I think your application is not finding the mysql connector jar file or your url is misconfigured.

Try the following

  1. Put your mysql connector jar file under tomcat/common/lib so that it gets picked up before the webapp classes.
  2. Change your context.xml to have Resource as below.

    
    
    
    <Resource  name="jdbc/exampleWeb"
        auth="Container"
        type="javax.sql.DataSource"
        maxActive="100"
        maxIdle="30"
        username="root"
        maxWait="10000"
        driverClassName="com.mysql.jdbc.Driver"
        password="roopt"  
        url="jdbc:mysql://localhost:3306/welcomeHub"/>
    

Upvotes: 2

Ben ODay
Ben ODay

Reputation: 21005

I've seen that same eror with DBCP and it usually means that it can't find the JDBC driver...make sure "com.mysql.jdbc.Driver" is available to the container

Upvotes: 0

axtavt
axtavt

Reputation: 242686

I can't understand why do you need both entityManagerFactory and sessionFactory, usually only one of them is needed.

If sessionFactory is not needed, remove it. Otherwise note that its datasource is not configured - I guess it's a cause.

Upvotes: -1

Related Questions