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

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

hibernate連的oracle數據庫測試junit報錯,請問是哪里錯了?

http://img1.sycdn.imooc.com//5730313b0001340a05940277.jpg

import?java.util.Date;

public?class?Students?{
	
	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?String?getAddress()?{
		return?address;
	}

	public?void?setAddress(String?address)?{
		this.address?=?address;
	}

	public?Date?getBirthday()?{
		return?birthday;
	}

	public?void?setBirthday(Date?birthday)?{
		this.birthday?=?birthday;
	}

	@Override
	public?String?toString()?{
		//?TODO?Auto-generated?method?stub
		return?"Students?[sid="?+?sid?+",sname="+?sname?+?",?gender="
				+?gender+",birthday?=?"+?birthday?+?",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">dbusrmkt</property>
?????<property?name="connection.password">futuremkt</property>
?????<property?name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
?????<property?name="connection.url">jdbc:oracle\:thin\:@172.17.11.60\:1521\:HDQTLS</property>
?????<property?name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
?????
?????<property?name="show_sql">true</property>
?????<property?name="format_sql">true</property>
?????<property?name="hbm2ddl.auto">create</property>
?????<property?name="hibernate.default_schema">dbusrmkt</property>
?????
?????<mapping?resource="Students.hbm.xml"/>
?????
????</session-factory>
</hibernate-configuration>

StudentsTest 測試類如下:


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

}

求教啊,謝謝!

正在回答

1 回答

Failure Trace第一行顯示的是什么?

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

zoeyqq 提問者

這個我已經弄好了,是那個配置文件放錯了
2016-05-10 回復 有任何疑惑可以回復我~
#2

sherenrui 回復 zoeyqq 提問者

ok^
2016-05-10 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

hibernate連的oracle數據庫測試junit報錯,請問是哪里錯了?

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

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

幫助反饋 APP下載

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

公眾號

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