我需要创建一个外键来映射我的表。基本上,这个外键是表的主键。但是插入语句正在引起问题。它是一个 SQLite 数据库。具有主键的表是
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ Main
+ "(ROWID integer primary key autoincrement NOT NULL,appln_date VARCHAR,appln_no VARCHAR,rupees VARCHAR,tenure VARCHAR,asset VARCHAR);");
带有外键的表是
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ Applicant
+ "(AppID integer primary key autoincrement, " +
"app_salutation VARCHAR,app_fname VARCHAR,app_mname VARCHAR,app_lname VARCHAR,app_door VARCHAR,app_street VARCHAR,app_building VARCHAR,app_area VARCHAR,app_post VARCHAR,app_tehsil VARCHAR,app_state VARCHAR,app_landmark VARCHAR,ROWID integer References "+Main+"(ROWID));");
插入语句是
openOrCreateDatabase();
createappinfo();
String insertString = "insert into " + Applicant
+ " Values(";
String inString = "";
for (int i =0; i < data.size(); i++) {
inString = inString + "\"" + data.get(i) + "\",";
}
inString = inString.substring(0, inString.length() - 1);
int row=db.rawQuery("select * from "+Main+";" ,null).getCount()+1;
insertString = insertString + row+"," +inString + ");";
System.out.println("** insert value ** " + insertString);
db.execSQL(insertString);
closeDatabase();
但是这段代码正在产生错误..
04-25 11:43:57.422: E/SQLiteLog(17825): (1) table applicanttable has 14 columns but 13 values were supplied