获取SQLException:Driver:org.hsqldb.jdbcDriver为tomee中的URL返回null [英] Getting SQLException: Driver:org.hsqldb.jdbcDriver returned null for URL in tomee

查看:124
本文介绍了获取SQLException:Driver:org.hsqldb.jdbcDriver为tomee中的URL返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跟踪已部署的应用程序中的异常.

I am getting following exception in tomee deployed application.

 [EL Severe]: 2014-07-11 09:18:34.811--ServerSession(860687693)--Thread(Thread[http-bio-8081-exec-3,5,main])--Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Driver:org.hsqldb.jdbcDriver@7078c2bb returned null for URL:"jdbc:mysql://localhost:3306/testDB"
Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:316)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:135)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:309)
    at org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createEntityManager(ReloadableEntityManagerFactory.java:159)
    at org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:115)
    at org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:91)
    at org.apache.openejb.persistence.JtaEntityManager.find(JtaEntityManager.java:164)

这是我的 tomee.xml 文件

<tomee>
  <Resource id="testDBPool" type="DataSource">
    jdbcDriverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost:3306/testDB"
    username = "admin"
    password = "admin"
  </Resource>
</tomee>

我已经将 mysql_connector jar放在我的 tomee/lib 文件夹中. 我的 persistence.xml 文件如下,

I already put mysql_connector jar in my tomee/lib folder. My persistence.xml file as below,

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="TestPersistence"
        transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/testDBPool</jta-data-source>
        <shared-cache-mode>NONE</shared-cache-mode>
        <properties>
            <property name="eclipselink.weaving" value="static" />
            <property name="eclipselink.logging.level.sql" value="FINEST" />
            <property name="eclipselink.logging.level" value="FINEST" />
            <property name="eclipselink.logging.level.cache" value="FINEST" />
        </properties>
    </persistence-unit>
</persistence>

我不明白我在哪里错了,为什么我会得到这个例外? 请帮我解决这个问题.

I do not understand where I am wrong, why I am getting this exception? Please help me to solve this.

推荐答案

问题是您使用了错误的属性名称来声明JDBC驱动程序.根据 Apache TomEE:数据源配置,驱动程序名称的属性为 jdbcDriver ,而不是jdbcDriverClassName. jdbcDriver的默认值为org.hsqldb.jdbcDriver.因此,正如我之前评论的那样,它将尝试使用HSQLDB创建连接,但使用MySQL JDBC URL.

The problem is that you are using the wrong property name to declare the JDBC driver. According to Apache TomEE: DataSource Configuration, the property for the driver name is jdbcDriver, and not jdbcDriverClassName. The default value for jdbcDriver is org.hsqldb.jdbcDriver. So as I commented earlier it will try to create a connection using HSQLDB, but with a MySQL JDBC url.

要解决您的问题,请将配置更改为:

To fix your problem change your configuration to:

<tomee>
  <Resource id="testDBPool" type="DataSource">
    jdbcDriver = "com.mysql.jdbc.Driver"
    ...
  </Resource>
</tomee>

这篇关于获取SQLException:Driver:org.hsqldb.jdbcDriver为tomee中的URL返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆