gpt4 book ai didi

java - 获取数据库信息时出错?在 EclipseLink 中与 Oracle

转载 作者:行者123 更新时间:2023-12-01 23:08:14 25 4
gpt4 key购买 nike

我正在使用 eclipselink 制作一个小型应用程序。当我尝试将数据插入数据库时​​,它抛出异常。

使用的技术有:

IDE:EclipseORM:EclipseLink平台:JAVA数据库:Oracle

以前我使用 MySql 工作得很好。当我更改数据库时,出现了问题。

下面是persistance.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="OracleDemo" transaction-type="RESOURCE_LOCAL">
<class>com.demo.UserDetails</class>
<properties>

<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:XE" />
<property name="javax.persistence.jdbc.user" value="testjpa" />
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
<property name="javax.persistence.jdbc.password" value="testjpa"/>

<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc" />
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />

</properties>
</persistence-unit>
</persistence>

我的InsertData.java

public class InsertData {

public static void main(String[] args) {

UserDetails userDetails = new UserDetails();
userDetails.setName("prabha");
userDetails.setCity("SKLM");

EntityManager entityManager = EntityManagerUtil.getEmf().createEntityManager();
try {
EntityTransaction entr = entityManager.getTransaction();
entr.begin();

entityManager.persist(userDetails);

entr.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
entityManager.close();
}
}
}

异常

[EL Info]: 2014-03-17 15:15:32.603--ServerSession(799611093)--EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Severe]: ejb: 2014-03-17 15:15:32.801--ServerSession(799611093)--Exception [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Error while obtaining information about the database. Refer to the nested exception for more details.
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Error while obtaining information about the database. Refer to the nested exception for more details.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
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:302)
at com.demo.ReadData.main(ReadData.java:14)
Caused by: Exception [EclipseLink-4019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Error while obtaining information about the database. Refer to the nested exception for more details.
at org.eclipse.persistence.exceptions.DatabaseException.errorRetrieveDbMetadataThroughJDBCConnection(DatabaseException.java:368)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:226)
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)
... 5 more

最佳答案

JDK 1.6结合的官方JAR文件是ojdbc6.jar。当您与Oracle11g一起使用而不是使用ojdbc14.jar时,请使用ojdbc6.jar

关于java - 获取数据库信息时出错?在 EclipseLink 中与 Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22450566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com