夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          <2009年7月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          公告

          本博客中未注原創的文章均為轉載,對轉載內容可能做了些修改和增加圖片注釋,如果侵犯了您的版權,或沒有注明原作者,請諒解

          常用鏈接

          留言簿(21)

          隨筆分類(644)

          隨筆檔案(669)

          文章檔案(6)

          最新隨筆

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          最近發現HIBERNATE可以動態更換表名,真不簡單,下面把原代碼貼出來供參考:

          public class ReportDBApi {

            private SessionFactory sessionFactory = null;
            public ReportDBApi(){
              createSession();
            }

            public void createSession(){
              Date date = new Date();
              SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
              String now_time = simpledateformat.format(date);
              String tablename = "TBL_REPORT_STATUS_20050707";
              tablename = "TBL_REPORT_STATUS_" + now_time;
              try {
                Configuration cfg = new Configuration().addClass(cn.sports.vas.sms.unicom.TblReportStatus.class).configure();

                Table table = cfg.getClassMapping(TblReportStatus.class).getTable();
                table.setName(tablename);
                cfg.getClassMapping(TblReportStatus.class).setTable(table);
                sessionFactory  = cfg.buildSessionFactory();
              }
              catch (MappingException ex) {
                ex.printStackTrace();
              }catch (HibernateException ex) {
                ex.printStackTrace();
              }
            }

            public void insertPO(TblReportStatus po) throws HibernateException {
              Session session = sessionFactory.openSession();
              Transaction tx = session.beginTransaction();
              session.save(po);
              tx.commit();
              session.close();
            }

            public void closeSession() throws HibernateException {
              sessionFactory.close();
            }
          }


          這個類是每天新建一張表,并往里寫數據。

           

          本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/jljf_hh/archive/2005/07/14/424510.aspx

          posted on 2009-07-16 23:20 HUIKK 閱讀(1833) 評論(1)  編輯  收藏

          評論

          # re: Hibernate 動態表名 2010-05-31 11:54 fff
          mei jishu hanliang  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 巴塘县| 永福县| 红河县| 应城市| 宣恩县| 永兴县| 台南县| 惠来县| 洛扎县| 七台河市| 青神县| 舟山市| 哈尔滨市| 封丘县| 天门市| 漯河市| 洪湖市| 舟山市| 昌图县| 东丰县| 廊坊市| 迁西县| 客服| 遵义市| 卢氏县| 古交市| 富源县| 兴安县| 朝阳县| 大荔县| 禹州市| 藁城市| 灵山县| 高台县| 平度市| 潮安县| 普格县| 三穗县| 辛集市| 灌南县| 新乡县|