第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Junit測試出錯,求教各位大佬

Junit測試出錯,求教各位大佬

慕粉3971981 2017-03-22 10:31:05
Ecplise版本 ?4.5.2hibernate版本 ?5.0.1junit版本 ?4.10mysql版本 ?5.5.44mysql-jdbc版本 ?5.1.41Students類import?java.util.Date; //持久化類 public?class?Students?{ private?int?sid; private?String?sname; private?String?gender; private?Date?birthday; private?String?address; public?Students(int?i,?String?sname,?String?gender,?Date?birthday,?String?address)?{ this.sid?=?i; 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; } }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"></property> ???? <property?name="connection.driver_class">com.mysql.jdbc.Driver</property> ???? <property?name="connection.url">jdbc:mysql:///hibernate?useUnicode=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?2017-3-22?0:40:09?by?Hibernate?Tools?3.5.0.Final?--> <hibernate-mapping> ????<class?name="Students"?table="STUDENTS"> ????????<id?name="sid"?type="java.lang.String"> ????????????<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>StudentsTestimport?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(){ //創(chuàng)建配置對象 Configuration?config=new?Configuration().configure(); //創(chuàng)建服務注冊對象 ServiceRegistry?serviceRegistry=new?StandardServiceRegistryBuilder(). applySettings(config.getProperties()).build(); //創(chuàng)建會話工廠對象 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(),"武當山"); //保存對象進入數(shù)據(jù)庫 session.save(s);?? } }截圖如下
查看完整描述

2 回答

?
偶爾喝個小酒

TA貢獻5條經(jīng)驗 獲得超1個贊

問題解決了嗎

查看完整回答
反對 回復 2018-03-01
  • 2 回答
  • 0 關注
  • 1313 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號