MySQL資料庫建立表報錯的解決方案

來源:互聯網
上載者:User

標籤:java   map   manual   err   sed   str   roo   log   --   

實體類package com.tao.pojo;public class Student {
private String id; private String name; private String pass; public Student() { super(); } public Student(String name, String pass) { super(); this.name = name; this.pass = pass; } public Student(String id, String name, String pass) { super(); this.id = id; this.name = name; this.pass = pass; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } @Override public String toString() { return "Student [id=" + id + ", name=" + name + ", pass=" + pass + "]"; }}對應檔<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Generated 2018-3-1 14:18:27 by Hibernate Tools 3.5.0.Final --><hibernate-mapping> <class name="com.tao.pojo.Student" table="STUDENT"> <id name="id" type="java.lang.String"> <column name="ID" /> <generator class="uuid" /> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <property name="pass" type="java.lang.String"> <column name="PASS" /> </property> </class></hibernate-mapping>設定檔<?xml version="1.0" encoding="UTF-8"?><!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> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test0228_002</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <mapping resource="com/tao/pojo/Student.hbm.xml"/> </session-factory></hibernate-configuration>測試package com.tao.test;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.hibernate.dialect.MySQL5Dialect;public class TestMain { //用hibernate架構建立表 public static void main(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 version for the right syntax to use near ‘type=MyISAM‘ at line 6解決方案將資料庫方言改為 <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

 

MySQL資料庫建立表報錯的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.