Java的面向對象數據庫db4o

          上學的時候就聽老師說過有對象數據庫。
          但是我所接觸的數據庫都是關系型數據庫mysql,oracle,ms sql server,或是db2.
          最近在ibm development work上看到一個名為db4o的對象數據。
          才看第一章,學過Java的都應該很容易理解的。
          確實它真的很簡單。
          看起來似乎就像是在一個Java的操作,而并非如我們所以為的那樣的想關系型數據庫中操作一樣。
          如果有興趣的話,大家也可以去看看。
          不過,文章作者也對db4o的一些缺點進行了列舉。
          自己并沒有進行很深入的學習。
          只是對其感興趣罷了。
          或許對系數據庫可能讓我們進入一個新的世界。
           1 public class Person
           2 {
           3     public Person()
           4     { }
           5     public Person(String firstName, String lastName, int age)
           6     {
           7         this.firstName = firstName;
           8         this.lastName = lastName;
           9         this.age = age;
          10     }
          11     
          12     public String getFirstName() { return firstName; }
          13     public void setFirstName(String value) { firstName = value; }
          14     
          15     public String getLastName() { return lastName; }
          16     public void setLastName(String value) { lastName = value; }
          17     
          18     public int getAge() { return age; }
          19     public void setAge(int value) { age = value; }
          20 
          21     public String toString()
          22     {
          23         return 
          24             "[Person: " +
          25             "firstName = " + firstName + " " +
          26             "lastName = " + lastName + " " +
          27             "age = " + age + 
          28             "]";
          29     }
          30     
          31     public boolean equals(Object rhs)
          32     {
          33         if (rhs == this)
          34             return true;
          35         
          36         if (!(rhs instanceof Person))
          37             return false;
          38         
          39         Person other = (Person)rhs;
          40         return (this.firstName.equals(other.firstName) &&
          41                 this.lastName.equals(other.lastName) &&
          42                 this.age == other.age);
          43     }
          44     
          45     private String firstName;
          46     private String lastName;
          47     private int age;
          48 }
          49 
          數據庫的insert
           1 
           2 import com.tedneward.model.*;
           3 
           4 public class Hellodb4o
           5 {
           6     public static void main(String[] args)
           7         throws Exception
           8     {
           9         ObjectContainer db = null;
          10         try
          11         {
          12             db = Db4o.openFile("persons.data");
          13 
          14             Person brian = new Person("Brian""Goetz"39);
          15             
          16             db.set(brian);
          17             db.commit();
          18         }
          19         finally
          20         {
          21             if (db != null)
          22                 db.close();
          23         }
          24     }
          25 }
          26 
          或是用另外的一種方法進行insert操作。
           1 public class Hellodb4o
           2 {
           3     public static void main(String[] args)
           4         throws Exception
           5     {
           6         ObjectContainer db = null;
           7         try
           8         {
           9             db = Db4o.openFile("persons.data");
          10 
          11             Person brian = new Person("Brian""Goetz"39);
          12             Person jason = new Person("Jason""Hunter"35);
          13             Person clinton = new Person("Brian""Sletten"38);
          14             Person david = new Person("David""Geary"55);
          15             Person glenn = new Person("Glenn""Vanderberg"40);
          16             Person neal = new Person("Neal""Ford"39);
          17             
          18             db.set(brian);
          19             db.set(jason);
          20             db.set(clinton);
          21             db.set(david);
          22             db.set(glenn);
          23             db.set(neal);
          24 
          25             db.commit();
          26             
          27             // Find all the Brians
          28             ObjectSet brians = db.get(new Person("Brian"null0));
          29             while (brians.hasNext())
          30                 System.out.println(brians.next());
          31         }
          32         finally
          33         {
          34             if (db != null)
          35                 db.close();
          36         }
          37     }
          38 }
          39 
          詳細介紹請參看ibm的學習文檔。
          http://www.ibm.com/developerworks/cn/java/jdb4o/?ca=j-h

          posted on 2009-06-09 13:34 duduli 閱讀(1556) 評論(3)  編輯  收藏 所屬分類: 數據庫

          評論

          # re: Java的面向對象數據庫db4o 2009-06-09 17:14 找個美女做老婆

          我的博客搬到新家了 http://www.javaly.cn, 順便給你推薦一個導航網站 http://www.510gougou.com  回復  更多評論   

          # re: Java的面向對象數據庫db4o 2009-06-10 09:45 subtitle

          .....  回復  更多評論   

          # re: Java的面向對象數據庫db4o 2009-06-13 09:40 metadmin

          您看看GAE,可以將對象托管起來。后臺編程更簡單了。

          ---------------------------------
          解開權限與業務耦合,提高開發效率
          細粒度權限管理軟件 試用版下載
          http://www.metadmin.com

            回復  更多評論   

          <2009年6月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導航

          統計

          公告

          welcome to my place.

          常用鏈接

          留言簿(5)

          我參與的團隊

          隨筆分類

          隨筆檔案

          新聞分類

          石頭JAVA擺地攤兒

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          @duduli
          主站蜘蛛池模板: 会泽县| 新丰县| 广宁县| 江陵县| 泾源县| 阿克陶县| 潞城市| 珲春市| 白水县| 邳州市| 安远县| 甘孜县| 白银市| 瓦房店市| 彩票| 鲁山县| 丹江口市| 沙坪坝区| 墨竹工卡县| 珲春市| 农安县| 天柱县| 那曲县| 大理市| 苍梧县| 潜山县| 武乡县| 乌兰浩特市| 诸城市| 张北县| 临桂县| 北安市| 斗六市| 丰城市| 精河县| 庆云县| 纳雍县| 依兰县| 自贡市| 门源| 来安县|