我想把SQL数据库放在一起,但不知道如何使它工作。意图是有多个列,一些是整数,一些是在单元格中有字符串。对于这个应用程序,我希望重复是一个整数,并锻炼成一个字符串。这里是代码的相关部分:SQL数据库类型问题
public static final String KEY_ROWID = "_id";
public static final String KEY_DATE = "date";
public static final String KEY_EXERCISE = "exercise";
public static final String KEY_REPS = "repetitions";
private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " ("
+ KEY_ROWID + " integer primary key autoincrement, "
+ KEY_DATE + " text not null, "
+ KEY_EXERCISE + " text not null, "
+ KEY_REPS + " int not null, "
public long createExercise(String exercise, int reps) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DATE, date);
initialValues.put(KEY_EXERCISE, exercise);
initialValues.put(KEY_REPS, reps);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
我把数据放在这个表中使用测试字符串。然后我尝试用以下查询来提取数据:
public Cursor graphQuery(String exercise, String workout) {
return mDb.query(DATABASE_TABLE, new String[] {KEY_DATE, KEY_REPS}, null, null,
null, null, null);
从那里我尝试将数据放入数组中,但它给了我一个错误。它告诉我在我宣布它时将KEY_REPS作为一个数字。但是,如果我将KEY_REPS声明为数字,它不会让我构建数据集。
Cursor cursor = mDbHelper.graphQuery(currentexercise, currentworkout);
startManagingCursor(cursor);
Number[] reps = new Number[]{workoutDbAdapter.KEY_REPS}; //error here
我觉得我缺少如何创建我的数据库的关键部分。谁能帮忙?
从书中我试图按照代码(除使用整数)(从第一个答案评论)话虽这么说,如果有人知道一个很好的网站,教的SQLite的,因为它适用于Android的
private void fillData() {
Cursor remindersCursor = mDbHelper.fetchAllReminders();
startManagingCursor(remindersCursor);
// Create an array to specify the fields we want (only the TITLE)
String[] from = new String[]{RemindersDbAdapter.KEY_TITLE};
那将是真棒。我唯一能找到的是通用SQL站点,它们并不是非常有用。
对于这一点,你问任何问题:请复制并粘贴错误消息的准确* *,因为他们出现了。简单地描述错误信息并不像粘贴它有用。与代码类似 - 我不确定是否按照您定义的方式显示“createExercise”,因为“date”未定义。 – 2011-06-14 17:11:23