mysql创建表怎么解决方案_MySQL数据库创建表报错的解决方案

本文档展示了如何使用Hibernate框架创建数据库表,并针对遇到的MySQLSyntaxErrorException错误进行了分析。错误源于方言设置不正确,解决方案是将数据库方言改为MySQL5Dialect。通过调整Hibernate配置文件和实体类,可以成功创建表并避免语法错误。
摘要由CSDN通过智能技术生成

实体类packagecom.tao.pojo;public classStudent {privateString id;privateString name;privateString pass;publicStudent() {super();

}publicStudent(String name, String pass) {super();this.name =name;this.pass =pass;

}publicStudent(String id, String name, String pass) {super();this.id =id;this.name =name;this.pass =pass;

}publicString getId() {returnid;

}public voidsetId(String id) {this.id =id;

}publicString getName() {returnname;

}public voidsetName(String name) {this.name =name;

}publicString getPass() {returnpass;

}public voidsetPass(String pass) {this.pass =pass;

}

@OverridepublicString toString() {return "Student [id=" + id + ", name=" + name + ", pass=" + pass + "]";

}

}

映射文件<?xml version="1.0"?>

/p>

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

配置文件<?xml version="1.0" encoding="UTF-8"?>

/p>

"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

com.mysql.jdbc.Driver

root

jdbc:mysql://localhost:3306/test0228_002

root

org.hibernate.dialect.MySQLDialect

true

true

update

测试packagecom.tao.test;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.cfg.Configuration;importorg.hibernate.dialect.MySQL5Dialect;public classTestMain {//用hibernate框架创建表

public static voidmain(String[] args) {

Configuration configure= new Configuration().configure("hibernate.cfg.xml");

SessionFactory factory=configure.buildSessionFactory();

Session session=factory.openSession();

session.beginTransaction();

session.getTransaction().commit();

session.close();

factory.close();

}

}

用程序生成表,如果报的有这个错

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versionfor the right syntax to use near ‘type=MyISAM‘ at line 6解决方案

将数据库方言改为org.hibernate.dialect.MySQL5Dialect

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值