首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >原因: java.sql.SQLSyntaxErrorException:表'project.playing‘不存在

原因: java.sql.SQLSyntaxErrorException:表'project.playing‘不存在
EN

Stack Overflow用户
提问于 2020-04-24 20:43:18
回答 1查看 2.5K关注 0票数 1

错误:由: com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120):表'project.playing‘不存在于com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)在com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)

在eclipse中,使用maven项目尝试使用hibernate在现有mysql数据库(项目)中创建一个表(播放)。实体类代码:

代码语言:javascript
运行
复制
package com.rj.hibtry.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "playing")
public class Users {

    @Id
    @Column(name = "user_id")
    int userId;

    @Column(name = "username")
    String username;

    @Column(name = "password")
    String password;

    @Column(name = "first_name")
    String firstName;

    @Column(name = "last_name")
    String lastName;


    public Users(String username, String password, String firstName, String lastName) {
        this.username = username;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}

主要方法代码:

代码语言:javascript
运行
复制
package com.rj.hibtry;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.rj.hibtry.entity.Users;

public class App {

    public static void main(String[] args) {
          SessionFactory factory=new Configuration()
                  .configure("hibernate.cfg.xml")
                  .addAnnotatedClass(Users.class)
                  .buildSessionFactory();
          Session session=factory.getCurrentSession();
          try {
              // Create object of entity class type
              Users user = new Users("lj", "password", "firstName", "lastName");
              // Start transaction
              session.beginTransaction();
              // Perform operation
              session.save(user);
              // Commit the transaction 
              session.getTransaction().commit();
              System.out.println("Row added!");


        } finally {
            session.close();
            factory.close();
        }


      }
}

hibernate.cfg.xml代码:

代码语言:javascript
运行
复制
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>

        <!-- Connection settings -->

        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
              <!-- Sample MySQL URL provided  -->  
        <property name="connection.url">jdbc:mysql://localhost:3306/project?serverTimezone=UTC</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="hbm2ddl.auto">create</property>

        <!-- Show SQL on console -->
        <property name="show_sql">true</property>



        <!--Setting Session context model -->
        <property name="current_session_context_class">thread</property>

    </session-factory>
</hibernate-configuration>
EN

回答 1

Stack Overflow用户

发布于 2022-01-30 08:57:34

使用MySQL高于4.0版本的用户需要更改配置文件中的方言。"org.hibernate.dialect.MySQLDialect"将一直工作到4.0版本,上面您需要使用"org.hibernate.dialect.MySQL5Dialect"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61417151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档