【问题标题】:Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1049内部异常:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知错误 1049
【发布时间】:2016-12-30 15:53:24
【问题描述】:

这应该很容易。我正在使用 Eclipselink 在 JPA 中编写一个玩具应用程序,而不是使用 SSL。当调用实体管理器时,我收到以下消息。我猜我的 persistence.xml 文件中缺少一个参数,但异常不是很具体。

    [EL Info]: 2016-08-23 13:28:04.574--ServerSession(1586463432)--EclipseLink, version: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
    Tue Aug 23 13:28:05 EDT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
...
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1049
    Error Code: 1049
@ em= Error message: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1049
    Error Code: 1049
    javax.persistence.PersistenceException: Exception [EclipseLink-4002]   (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:    Unknown error 1049
    Error Code: 1049
    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.ruleagents.hero.Main.main(Main.java:48)
    Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1049
    Error Code: 1049
    at  org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:326)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
    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)
    ... 5 more
...
    Exception in thread "main" java.lang.NullPointerException
    at com.ruleagents.hero.Main.main(Main.java:62)

这是persistence.xml

<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="CharacterManager"
    transaction-type="RESOURCE_LOCAL">
    <provider>
       org.eclipse.persistence.jpa.PersistenceProvider
    </provider>
    <class>com.ruleagents.hero.Hero</class>
    <class>com.ruleagents.hero.Logon</class>
    <!-- class>com.ruleagents.hero.Stat</class -->
    <properties>
        <property name="javax.persistence.jdbc.driver" value='com.mysql.jdbc.Driver' />
        <property name="javax.persistence.jdbc.url"
            value="jdbc:mysql://localhost:3306/CharacterManager" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
        <property name="useSSL" value="false" />
        <property name="javax.persistence.jdbc.user" value="root"/>
    </properties>
</persistence-unit>
</persistence>

这就是它的名称:

public static EntityManagerFactory getEMF (){
    try {
        if (emf == null){
            emf = Persistence.createEntityManagerFactory("CharacterManager");
...
EntityManager em = null;
try {
   em = getEMF().createEntityManager();
   em.getTransaction().begin();
   em.persist(user);

我需要更改哪些内容才能连接到 MySql?谢谢!

【问题讨论】:

标签: java mysql jpa jdbc eclipselink


【解决方案1】:

MySQL 错误代码 1049 似乎是未知数据库。

Error: 1049 SQLSTATE: 42000 (ER_BAD_DB_ERROR)

Message: Unknown database '%s'

https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

【讨论】:

    猜你喜欢
    • 2012-07-20
    • 2011-12-15
    • 1970-01-01
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 2012-04-20
    相关资源
    最近更新 更多