2011-03-08 92 views
1

我對ORMLIte website上列出的例子有兩個問題。基本的ORMLite數據庫問題

  • 我在哪裏放數據庫,我該如何導入它?
  • 我把DAO和連接工廠放在哪個類?
+3

什麼網站?導入什麼? – jzd 2011-03-08 15:15:02

+0

我試圖運行這個http://ormlite.com/docs/example-simple並通過這個:http://ormlite.com/docs/getting-started – Alex 2011-03-08 15:17:22

+0

亞歷克斯,你還問了用戶郵件列表同樣的問題。請考慮從堆棧溢出中刪除它。它沒有提供關於你的配置的足夠信息(android,jdbc?),以便其他人可以提供幫助。我會在郵件列表上回復。 – Gray 2011-03-08 16:27:59

回答

0

我在哪裏放數據庫,我該如何導入它。

你的意思是h2 jar文件嗎?正如入門文檔(1.4代碼示例)中所述,您需要將h2 jar文件添加到類路徑中。如果您不確定如何設置類路徑,請首先進行調查,因爲這是Java中一個非常重要的概念。

0

你必須創建註釋數據庫模型 @DatabaseTable()

@DatabaseField()

像:

@DatabaseTable(tableName="YOUR_TABLE_NAME") 
public class SimpleDataModel { 
    @DatabaseField(id=true) 
    private int idSimpleData; 
    @DatabaseField() 
    private String NameSomeDataHere; 
} 

你不必要導入它,只需創建一個擴展到ORMSqliteOpenHelper的Helper類。

這是很好的文件,只需在ORMLite網站上搜索一下。但一個例子是:

public class dbHelper extends ORMSqliteOpenHelper { 
    onCreate() { // I'm letting some code behind, as long as Eclipse do implement methods for you. ;) 
     TableUtils.CreateTable(connectionSource, SimpleDataModel.class); 
     //This one above is what is going to create your tables. 
     //Afterwards you have to use DAO's to access your data, os it's nonsense. 
     //So if you're a begginner at android just read the ENTIRE documentarion of ORMLite, and MAYBE you'll understand something ;P   

}