亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

hibernate報錯 org.hibernate.exception.SQLGrammarException: could not execute statement

hibernate報錯 org.hibernate.exception.SQLGrammarException: could not execute statement

好好認真學習 2017-03-19 13:54:57
package hibernate;import java.util.Date;public class Student {? ? ? private int sid;? ? ? private String sname;? ? ? private String gender;? ? ? private Date birthday;? ? ? private String address;? ? ??? ? ?? ? ? public Student(int sid,String sname,String gender,Date birthday,String address){? ? ?this.sid=sid;? ? ?this.sname=sname;? ? ?this.gender=gender;? ? ?this.birthday=birthday;? ? ?this.address=address;? ? ?? ? ? }?public Student(){? ? ?? ? ?? ? ? } public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; }? ? ??}<?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 2017-3-18 17:32:20 by Hibernate Tools 3.5.0.Final --><hibernate-mapping>? ? <class name="hibernate.Student" table="STUDENT">? ? ? ? <id name="sid" type="int">? ? ? ? ? ? <column name="SID" />? ? ? ? ? ? <generator class="assigned" />? ? ? ? </id>? ? ? ? <property name="sname" type="java.lang.String">? ? ? ? ? ? <column name="SNAME" />? ? ? ? </property>? ? ? ? <property name="gender" type="java.lang.String">? ? ? ? ? ? <column name="GENDER" />? ? ? ? </property>? ? ? ? <property name="birthday" type="java.util.Date">? ? ? ? ? ? <column name="BIRTHDAY" />? ? ? ? </property>? ? ? ? <property name="address" type="java.lang.String">? ? ? ? ? ? <column name="ADDRESS" />? ? ? ? </property>? ? </class></hibernate-mapping>package hibernate;import java.util.Date;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.boot.registry.StandardServiceRegistryBuilder;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.junit.After;import org.junit.Before;import org.junit.Test;public class StudentsTest { ? private SessionFactory sessionFactory; ? private Session session; ? private Transaction transaction; @Before public void init(){ //創建配置對象 Configuration config=new Configuration().configure(); config.addClass(Student.class); //創建服務注冊對象 ServiceRegistry serviceRegistry =new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build(); //創建會話工廠對象 sessionFactory=config.buildSessionFactory(serviceRegistry); //會話對象 session=sessionFactory.openSession(); //開啟事物 transaction=session.beginTransaction(); } @After public void destroy(){ transaction.commit();//提交事物 session.close();//關閉會話 sessionFactory.close();//關閉會話工廠 } @Test public void testSaveStudent(){ Student s=new Student(2,"張三","男",new Date(),"麗水"); session.save(s); }}<?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="connection.username">root</property>? ? <property name="connection.password">123456</property>? ? <property name="connection.driver_name">com.mysql.jdbc.Driver</property>? ? <property name="connection.url">jdbc:mysql://localhost:3306/student</property>? ? ?<property name="dialect">org.hibernate.dialect.MySQLDialect</property>?? ? ?? ? ?<property name="show_sql">true</property>? ? ?<property name="format_sql">true</property>? ? ?<property name="hbm2dd1.auto">create</property>? ? <mapping resource="Student.hbm.xml"/>? ? </session-factory></hibernate-configuration>
查看完整描述

2 回答

?
習慣受傷

TA貢獻885條經驗 獲得超1144個贊

你看一下控制臺輸出的sql語句是什么樣的?

查看完整回答
1 反對 回復 2017-03-19
  • 習慣受傷
    習慣受傷
    Table 'student.student' doesn't exist,表不存在哈,<property name="hibernate.hbm2ddl.auto">create</property> 是不是你的配置有點問題呢?
  • 好好認真學習
    好好認真學習
    hibernate-release-5.2.9.Final junit4.9 mysql使用5.1.29
  • 好好認真學習
    好好認真學習
    換了個數據庫還是沒用
點擊展開后面1
  • 2 回答
  • 0 關注
  • 1810 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號