1
這裏是我的代碼,與無關的東西去掉:Android的 - SQL語法錯誤
public class DataManager extends SQLiteOpenHelper
{
private final static String DB_TABLE = "Nums";
private ContentValues initialValues;
private static SQLiteDatabase myDB;
public DataManager()
{
initialValues = new ContentValues();
if(null != myDB)
{myDB.close();}
myDB = getWritableDatabase(); // This causes NullPointerException which is next on my TODO list
}
public void addValues(String num, String val)
{
initialValues.clear();
initialValues.put(num,val);
myDB.insert(DB_TABLE, null, initialValues); // THIS LINE CAUSES ERROR
}
}
我可以CREATE
數據庫,但我不能沒有INSERT
收到此錯誤: android.database.sqlite.SQLiteException: near "1": syntax error: , while compiling: INSERT INTO Nums(1) VALUES(?);
數據庫表Nums
看起來是這樣的:
Num | Val
=========
1 | 23
2 | 34
3 | 6
4 | 3
5 | 5
6 | 56
7 | 34
8 | 45
9 | 32
10 | 23
正如你所看到的,我試圖創建一個數據庫的Wi從1 - > n中的數字列表,其中每個數字旁邊都有一個值。數據庫中的所有值都是String
。有一個原因,我沒有選擇INT
但現在不記得.... :(
任何人都可以看到我的語法有錯嗎? 我的手機紮根,所以我可以用一個SQLite瀏覽應用查看數據庫,該表創建,它只是空!
感謝。
啊好吧,你們讓我顯然用錯了。現在有道理,謝謝! – eoinzy