插入时出现Android SQLite错误

时间:2016-05-21 02:08:12

标签: android sqlite

我在这里遇到一个非常奇怪的错误

android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: INSERT INTO course(banner_image,image,subtitle,homepage,short_summary,expected_learning,,new_release,syllabus,title,slug,key,featured,summary,faq,starter,project_description,required_knowledge,project_name,level,full_course_available) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

我的查询中有2个连续的逗号。问题是我正在使用ContentValues类构建我的insert语句,如此

private ContentValues createCourseValues(){
    ContentValues courseValues = new ContentValues();
    courseValues.put(CourseContract.Course.SUBTITLE, "Starting Out with Web Serving Technology");
    courseValues.put(CourseContract.Course.KEY, "ud171");
    courseValues.put(CourseContract.Course.IMAGE, "avc");
    courseValues.put(CourseContract.Course.EXPECTED_LEARNING, "You want to build Web services");
    courseValues.put(CourseContract.Course.FEATURED, false);
    courseValues.put(CourseContract.Course.PROJECT_NAME, "asd");
    courseValues.put(CourseContract.Course.TITLE, "Intro to Backend");
    courseValues.put(CourseContract.Course.REQUIRED_KNOWLEDGE, "You have a basic working knowledge ");
    courseValues.put(CourseContract.Course.SYLLABUS, "### Forms and Inputs How do web sites security?");
    courseValues.put(CourseContract.Course.NEW_RELEASE, false);
    courseValues.put(CourseContract.Course.HOMEPAGE, "https://www.udacity.com/course/" );
    courseValues.put(CourseContract.Course.PROJECT_DESCRIPTION, "");
    courseValues.put(CourseContract.Course.FULL_COURSE_AVAILABLE, false);
    courseValues.put(CourseContract.Course.FAQ, "ads");
    courseValues.put(CourseContract.Course.BANNER_IMAGE, "xc bv");
    courseValues.put(CourseContract.Course.SHORT_SUMMARY, "cvxdf");
    courseValues.put(CourseContract.Course.SLUG, "intro-to-backend--ud171");
    courseValues.put(CourseContract.Course.STARTER, false);
    courseValues.put(CourseContract.Course.LEVEL, "sdf s");
    courseValues.put(CourseContract.Course.DURATION_IN_HOURS, 504);
    courseValues.put(CourseContract.Course.SUMMARY, "This course presents an overview.");

我已经进行了搜索,并且在任何地方都没有找到2个逗号(事实上,如果是Java会对我很生气)我不明白为什么有2个逗号。我觉得登录中有更深层次的东西,我没有。

这就是我插入的方式

CourseDBHelper courseDBHelper = new CourseDBHelper(mContext);
    SQLiteDatabase db = courseDBHelper.getWritableDatabase();

    ContentValues courseValues = createCourseValues();
    long rowID = db.insertOrThrow(CourseContract.Course.TABLE_NAME, null, courseValues);
    assertTrue(rowID != -1);

Github link here

2 个答案:

答案 0 :(得分:1)

关于INSERT的粘贴Exception确实在...expected_learning,,new_release...

处有连续的逗号

查看您的回购邮件我想也许您错过了将CourseContract.Course.DURATION_IN_HOURS的值传递到该插入内容,使其显示为连续的逗号。

答案 1 :(得分:1)

我找到了你的问题。在CourseContract班级中,以下字段为空:

public static final String DURATION_IN_HOURS = "";

我把它改为:

public static final String DURATION_IN_HOURS = "duration_in_hours";

并且测试通过了。