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

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

如何在jsp中調(diào)用hibernate

StudentDao類:
package?com.dao;

/*import?java.util.ArrayList;
import?java.util.List;*/

import?org.hibernate.Session;
import?org.hibernate.SessionFactory;
import?org.hibernate.Transaction;
import?org.hibernate.cfg.Configuration;
/*import?org.hibernate.query.Query;*/

import?com.student.Student;

public?class?StudentDao?{
	
	public?Student?getById(int?id){
		Configuration?cfg=new?Configuration().configure();
		SessionFactory?sessionFactory=cfg.buildSessionFactory();
		Session?session=sessionFactory.openSession();
		Transaction?tran=session.beginTransaction();
		Student?s=session.get(Student.class,?id);
		tran.commit();
		session.close();
		return?s;
	}
	
}

jsp代碼:
<%
	StudentDao?dao=new?StudentDao();
	Student?s=dao.getById(13);
%>
<table>
	<tr>
		<td><%=s.getName()?%></td>
		<td><%=s.getNumber()?%></td>
		<td><%=s.getBirthday()?%></td>
	</tr>
提示Configuration?cfg=new?Configuration().configure();這一行代碼有錯(cuò),可是我寫的測試類可以成功過去s,在jsp頁面中調(diào)用
就有錯(cuò),類已經(jīng)導(dǎo)入了,數(shù)據(jù)庫也有數(shù)據(jù),是運(yùn)行時(shí)的錯(cuò)誤。

正在回答

3 回答

hibernate2.5是不用Configure創(chuàng)建對象的

0 回復(fù) 有任何疑惑可以回復(fù)我~
<%@?page?language="java"?contentType="text/html;?charset=UTF-8"
????pageEncoding="UTF-8"%>?????
<%@page?import="pojo.Students"%>
<%@page?import="test.StudentTest"%>
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8">
<%!
????StudentTest?studentTest=new?StudentTest();
????Students?s=studentTest.test();
%>
<title>Test</title>
</head>
<body>
????
????<label><%=s.getSid()?%></label>
????<label><%=s.getSname()?%></label>
????<label><%=s.getGender()?%></label>
????<label><%=s.getBirthday()?%></label>
????<label><%=s.getAddress()?%></label>
</body>
</html>

lib下引入包,jsp文件中引入java類,數(shù)據(jù)庫中要有數(shù)據(jù)。。。。


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕容8326568 提問者

這些我都做了,運(yùn)行時(shí)提示 Configuration cfg=new Configuration().configure();這一行出錯(cuò),但是我寫的測試類并沒有問題。
2017-09-22 回復(fù) 有任何疑惑可以回復(fù)我~

什么錯(cuò)誤?你倒是貼出來呀

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

如何在jsp中調(diào)用hibernate

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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