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