2 回答

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊
我終于想通了這一點(diǎn)。這CNAME在下面的命令應(yīng)該是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貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
這是獲取句柄和查詢(xún)的方法:
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();
}
...
}
添加回答
舉報(bào)