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

為了賬號安全,請及時綁定郵箱和手機立即綁定

大神幫忙?。。?!找不到students表,ERROR: Table 'hibernate.students' doesn't exist

hibernate.cfg.xml:

<?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">root</property>
?? ??? ?<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
?? ??? ?<property name="connection.url">jdbc:mysql:///hibernate?userUnicode=true&amp;characterEncoding=UTF-8</property>? ??? ?
?? ??? ?<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
?? ??? ?<property name="show_sql">true</property>
?? ??? ?<property name="format_sql">true</property>? ??? ?
?? ??? ?<property name="hbm2ddl.auto">create</property>
?? ??? ?<mapping resource="Students.hbm.xml"/>
??? </session-factory>
</hibernate-configuration>


Students.hbm.xml:

<?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 2016-4-3 15:32:14 by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
??? <class name="Students" table="STUDENTS">
??????? <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>


Students.java


import java.util.Date;

//學生類
public class Students {
?? ?// 1.共有的類
?? ?// 2.提供共有的不帶參數的默認的構造方法
?? ?// 3.屬性私有
?? ?// 4.屬性getter/setter方法

?? ?private int sid;
?? ?private String sname;
?? ?private String gender;
?? ?private Date birthday;
?? ?private String address;

?? ?public Students() {

?? ?}

?? ?public Students(int sid, String sname, String gender, Date birthday, String address) {
//?? ??? ?super();
?? ??? ?this.sid = sid;
?? ??? ?this.sname = sname;
?? ??? ?this.gender = gender;
?? ??? ?this.birthday = birthday;
?? ??? ?this.address = address;
?? ?}

?? ?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;
?? ?}

?? ?@Override
?? ?public String toString() {
?? ??? ?return "Students [sid=" + sid + ", sname=" + sname + ", gender=" + gender + ", birthday=" + birthday
?? ??? ??? ??? ?+ ", address=" + address + "]";
?? ?}
?? ?
?? ?
}


StudentsTest.java

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
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();
?? ??? ?//創建服務注冊對象
?? ??? ?ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
?? ??? ?//創建會話工廠對象
?? ??? ?sessionFactory=config.buildSessionFactory(serviceRegistry);
?? ??? ?//會話對象
?? ??? ?session=sessionFactory.openSession();
?? ??? ?//開啟事物
?? ??? ?transaction=session.beginTransaction();
?? ??? ?
?? ?}
?? ?
?? ?@After
?? ?public void destory(){
?? ??? ?transaction.commit();
?? ??? ?session.close();
?? ??? ?sessionFactory.close();
?? ??? ?
?? ?}
?? ?
?? ?@Test
?? ?public void testSaveStudents(){
?? ??? ?Students s=new Students(1,"張三豐","男",new Date(),"武當山");
?? ??? ?session.save(s);
?? ?}
}

正在回答

2 回答

要不使用自己的數據庫連接下 jdbc:mysql://localshost:3306

0 回復 有任何疑惑可以回復我~
#1

沉寂的蝸牛 提問者

謝謝你。。。應該是eclipse,或者mysql抽風了,隔了兩天再試試又有用了
2016-04-06 回復 有任何疑惑可以回復我~

你mysql 的數據庫有嗎

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

大神幫忙?。。?!找不到students表,ERROR: Table 'hibernate.students' doesn't exist

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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