熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

在Tomcat下配置Hibernate的開發環境[4]

2022-06-13   來源: Java開源技術 

Cat c;
c = new Cat();
csetName(name);
hsessionsave(c);
hsessionflush();
txcommit();
HibernateUtilcloseSession();
outprintln(Done);
}
%>
Add New Cats:<br>
<form method=post action=addCatjsp>
Name:<input name=name><br>
<input type=submit name=Go value=Add><br>
</form>
</body>
</html>

  第六個文件 getCatsjsp

<%@ page contentType=text/html; charset=GB %>
<%@ page import=hb* netsfhibernate*
javautil* %>
<html>
<head>
<title>Hibernate Test</title>
</head>
<body bgcolor=#ffffff]
<h>Test Hibernate</h>
<a href=addCatjsp>Add Cat[/url]<br>
<p> ID Name </p>
<%
SessionFactory sessionFactory;
netsfhibernateSession hsession;
hsession = HibernateUtilcurrentSession();
Transaction tx = hsessionbeginTransaction();
Query query = hsessioncreateQuery (select cat from Cat as cat );
for (Iterator it = queryiterate(); ithasNext();) {
Cat cat = (Cat) itnext();
outprintln(catgetId()+&nbsp; + catgetName() + <br>);
}
txcommit();
HibernateUtilcloseSession();
outprintln(Done);
%>
</body>
</html>

  說明

  對HibernateUtiljava的編譯

  javac classpath /lib/hibernatejar HibernateUtiljava

  有個警告可以忽略之

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29030.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.