【发布时间】:2013-02-27 13:40:39
【问题描述】:
我在 Sqlite 数据库中有两个表。第一个表的列是 _id as primary key, note date and _cid as foreign key 。第二个表的列是_cid as primary key, Category。
一些默认记录,我在创建第二个表时已插入。
两个表都已成功创建。 但是当我在第一个表中插入记录时没有插入。没有得到任何类型的异常。请指导我。
Table 1
private static final String DB__CREATE1 =
"CREATE TABLE " + TABLE_NAME_CATE +
"(_cid INTEGER PRIMARY KEY AUTOINCREMENT, "+
"Category TEXT not null);";
Table 2
private static final String DB__CREATE2 =
"CREATE TABLE " + TABLE_NAME +
"(_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
"Note TEXT not null, "+
"NoteDateTime TEXT not null, " +
"_cid INTEGER not null, " +
"FOREIGN KEY(_cid) REFERENCES Categories(_cid));";
插入数据的方法
publicvoidinsertData1( long c_id, String discription, String nDate){
ContentValues contentValues=new ContentValues();
contentValues.put("note", discription);
contentValues.put("date", nDate);
contentValues.put("_cid", c_id);
open();
database.insert("TABLE_NAME", null,contentValues);
close();
}`
调用语句
dbConnector.insertData1(1, textview.getText().toString(), nDateTime.toString());
【问题讨论】:
-
您需要发布您的代码。用您提供的内容无法调试您的问题。
-
那么,你有什么尝试??
-
您可以使用 Log.i("tag", e); 打印该异常;
-
我已经放了一些代码@Phil