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ò)誤。
2017-09-25
hibernate2.5是不用Configure創(chuàng)建對象的
2017-09-22
lib下引入包,jsp文件中引入java類,數(shù)據(jù)庫中要有數(shù)據(jù)。。。。
2017-09-21
什么錯(cuò)誤?你倒是貼出來呀