2 回答
TA贡献1934条经验 获得超2个赞
我终于想通了这一点。这CNAME在下面的命令应该是Craft_Name。
db.execSQL("INSERT INTO " + TABLE_NAME + "(CNAME, First_Attribute, Second_Attribute, Third_Attribute, Fourth_Attribute, Fifth_Attribute ) " +
"VALUES ('Landscape Drawing', '1', '4','8', 'NONE', 'NONE')");
TA贡献1790条经验 获得超9个赞
这是获取句柄和查询的方法:
public DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "crafts.db";
private static final String TABLE_CRAFT_TOOLS = "craft_tools";
private static final String KEY_CRAFT_NAME = "craft_name";
protected static SQLiteDatabase db = null;
/** Constructor */
public SqliteBaseHelper(Context context, String name, CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
if(db == null) {db = getWritableDatabase();}
}
/** this method possibly belongs into the helper class */
public String getString(int firstSelection, int secondSelection, int thirdSelection, int fourthSelection, int fifthSelection) {
StringBuilder sb = new StringBuilder();
String sql = "SELECT " + KEY_CRAFT_NAME + " FROM " + TABLE_CRAFT_TOOLS + " WHERE " +
"First_Attribute=? AND " +
"Second_Attribute=? AND " +
"Third_Attribute=? AND " +
"Fourth_Attribute=? AND " +
"Fifth_Attribute=? ";
String[] selectionArgs = new String[] {
Integer.toString(firstSelection),
Integer.toString(secondSelection),
Integer.toString(thirdSelection),
Integer.toString(fourthSelection),
Integer.toString(fifthSelection)
};
try {
Cursor cursor = db.rawQuery(sql, selectionArgs);
if (cursor.moveToFirst()) {
do {
sb.append(cursor.getString(cursor.getColumnIndex(KEY_CRAFT_NAME)) + "/n");
} while(cursor.moveToNext());
} else {
Log.w(LOG_TAG, "no crafts found.");
}
} catch (SQLiteException e) {
Log.e(LOG_TAG, e.getMessage());
} finally {
if (! cursor.isClosed()) {
cursor.close();
}
}
return sb.toString();
}
...
}
添加回答
举报