我开发了一个使用sqlite数据库的android应用程序。


主要问题:
*我一直没有这个专栏来面对这个错误,但是我只是找不到导致这个问题的原因。任何意见,将不胜感激。*
次要问题:
我希望该应用程序检查用户的信息是否在数据库内部。如果不存在,我希望系统在某些方面运行。如何进行检查?我尝试了以下类似的方法。但是由于没有这样的专栏问题,我不确定它是否有效。

                String values[] = helper.get_synccontentByEmailID(SettingConstant.EMAIL);
            if(!(values[0] == null)){


            }



-数据库类-

    public void onCreate(SQLiteDatabase db) {

    db.execSQL("CREATE TABLE synccontent (" +
            "tableid INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "emailid_sync TEXT " +
            "contentid TEXT," +
            "contentpath TEXT," +
            "filesize TEXT," +
            "createdtime TEXT,"+
            "createdate TIMESTAMP default current_timestamp);");
}
public String[] get_synccontentByEmailID(String emailid_sync){
    SQLiteDatabase myDB = null;
    String[] returnMsg = null;
    myDB = this.getReadableDatabase();

    Cursor c = myDB.rawQuery("SELECT tableid, emailid_sync, contentid, contentpath, filesize, createdtime" +
            " from synccontent where emailid_sync='"+emailid_sync+"' ", null);
    int emailid_syncColumn = c.getColumnIndex("emailid_sync");
    int contentidColumn = c.getColumnIndex("contentid");
    int contentpathColumn = c.getColumnIndex("contentpath");
    int filesizeColumn = c.getColumnIndex("filesize");
    int createdtimeColumn = c.getColumnIndex("createdtime");

    if (c.moveToFirst()) {
        do {
            returnMsg = new String[5];
            String contentid = c.getString(contentidColumn);
            String contentpath = c.getString(contentpathColumn);
            String filesize = c.getString(filesizeColumn);
            String createdtime = c.getString(createdtimeColumn);

            returnMsg[0] = emailid_sync;
            returnMsg[1] = contentid;
            returnMsg[2] = contentpath;
            returnMsg[3] = filesize;
            returnMsg[4] = createdtime;

        } while (c.moveToNext());
    }


- 主要活动 -

    syncButton = (Button) findViewById(R.id.sync_btn);
    syncButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {

                    String values[] = helper.get_synccontentByEmailID(SettingConstant.EMAIL);
                if(!(values[0] == null)){


                }





E/AndroidRuntime(4543): android.database.sqlite.SQLiteException: no such column: contentid: , while compiling: SELECT tableid, emailid_sync, contentid, contentpath, filesize, createdtime from wbm_synccontent where emailid_sync='[email protected]'

最佳答案

emailid_sync TEXT之后缺少逗号。

db.execSQL("CREATE TABLE synccontent (" +
            "tableid INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "emailid_sync TEXT, " +
            "contentid TEXT," +
            "contentpath TEXT," +
            "filesize TEXT," +
            "createdtime TEXT,"+
            "createdate TIMESTAMP default current_timestamp);");


那应该解决主要问题,在另一个答案中给出了解决次要问题的方法。我觉得很好

08-04 07:33