org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法创建类“”的 JDBC 驱动程序对于连接 URL“null”
我正在使用 spring、hybernate +jpa 开发一个基于 Web 的项目。我正在尝试使用 Atomkios 配置 JTA 事务 我的后端是mySql。我无法将应用程序设置为与 mySql 一起使用。 我的网络服务器是 tomcat 5.5。我正在尝试校准 jndi 配置的数据源..这里我的代码是
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>
我在 tomcat 5.5
Apache Software Foundation\Tomcat 5.5\conf.xml 中配置了 jndi :
<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>
我的服务器运行良好,但是当我尝试访问数据库数据时,我在 Web 浏览器中收到以下错误
org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取 JDBC 连接;嵌套异常是 org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法为连接 URL 'null' 创建类 '' 的 JDBC 驱动程序 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
帮助我
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您的应用程序没有找到 mysql 连接器 jar 文件或者您的 url 配置错误。
尝试以下方法
更改您的 context.xml 以包含如下资源。
<前><代码>
I think your application is not finding the mysql connector jar file or your url is misconfigured.
Try the following
Change your context.xml to have Resource as below.
我在 DBCP 中看到过同样的错误,这通常意味着它找不到 JDBC 驱动程序...确保“com.mysql.jdbc.Driver”可用于容器
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
我不明白为什么你需要
entityManagerFactory
和sessionFactory
,通常只需要其中之一。如果不需要
sessionFactory
,请将其删除。否则请注意,其数据源未配置 - 我猜这是一个原因。I can't understand why do you need both
entityManagerFactory
andsessionFactory
, 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.