XfoxKing's Blog

          喜愛(ài)Java
          隨筆 - 12, 文章 - 0, 評(píng)論 - 2, 引用 - 0

          導(dǎo)航

          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          公告


          流量統(tǒng)計(jì):

          常用鏈接

          留言簿

          隨筆檔案(12)

          相冊(cè)

          我的網(wǎng)站

          搜索

          •  

          積分與排名

          • 積分 - 4907
          • 排名 - 3105

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          MyEclipse中Hibernate的一些使用

          選擇導(dǎo)航菜單,MyEclipse –> Project Capabilities –> Add Hibernate Capabilities…

          image

          為了以后能獨(dú)立運(yùn)行,修改一下JAE Library Installation

          image

          Hibernate有全局的配置文件hibernate.cfg.xml,現(xiàn)在需要做一下配置

          image

          下一步需要注意的是對(duì)&字符進(jìn)行轉(zhuǎn)義

          jdbc:mysql://localhost:3306/studio?useUnicode=true&amp;characterEncoding=GBK

          image

          image

          Ok,創(chuàng)建完成,看一下配置的東西吧

          image

          接下來(lái)是Hibernate的具體使用,看一下所謂的反向工程吧。。。。

          單擊右鍵在需要用Hibernate的表格,選擇Hibernate Reverse Engineering,

          image

          現(xiàn)在對(duì)其做一下設(shè)置,最終如下

          image

          下一步

          image

          再下一步

          image

          看一下生成的文件吧

          image

          現(xiàn)在用Hibernate進(jìn)行一些編程測(cè)試吧

          import java.util.*;
          import java.sql.*;
          
          import org.hibernate.Transaction;
          
          public class Main {
          
          	/**
          	 * 
          	 * @param args
          	 */
          	public static void main(String[] args) {
          		//插入數(shù)據(jù)
          		
          		//1.實(shí)例化DAO
          		EchoUserLoginDAO dao = new EchoUserLoginDAO();
          		
          		//2.打開(kāi)transaction
          		Transaction tran = dao.getSession().beginTransaction();
          		
          		//3.生產(chǎn)Java類(lèi)
          		EchoUserLogin userlogin = new EchoUserLogin();
          		
          		//4.設(shè)置屬性
          		userlogin.setPassWord("xx");
          		userlogin.setUserName("yy");
          		
          		//5.保存
          		dao.save(userlogin);
          		
          		//6.提交事務(wù)
          		tran.commit();
          		
          		//7.讀取數(shù)據(jù)
          		java.util.List<EchoUserLogin> result = dao.findAll();
          		
          		//8.列出列表中的所有數(shù)據(jù)
          		for(EchoUserLogin o:result){
          			System.out.println(o.getUserName());
          			System.out.println(o.getPassWord());
          		}
          		dao.getSession().close();		
          	}
          }
          

          posted on 2009-10-26 07:37 XfoxKing 閱讀(455) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 梓潼县| 曲阜市| 马公市| 绍兴县| 漳州市| 常熟市| 永靖县| 永嘉县| 铜鼓县| 西充县| 出国| 文成县| 木兰县| 瑞丽市| 鲁甸县| 托里县| 洛扎县| 敦煌市| 甘孜| 石河子市| 自治县| 临沭县| 灌南县| 曲周县| 镇远县| 长沙县| 墨脱县| 绥芬河市| 泰州市| 临澧县| 白沙| 乐至县| 枝江市| 秦安县| 桦南县| 利辛县| 那坡县| 徐水县| 逊克县| 壶关县| 临沭县|