无法将数据保存到我的数据库中...应用已结束

时间:2011-02-02 15:44:57

标签: android sql save

嘿大家;)我又有了一个新问题:D 我现在可以打开我的应用程序并将数据插入到字段中,但是当我单击save-menu-item时它会中止...我发布了一段代码,我认为错误所在。 希望你能帮助我;)

//KFZ-Daten updaten (UPDATE)        
                if(getIntent().hasExtra("id") == true)
                {
                    long l = getIntent().getExtras().getLong("id");
                    myDB.execSQL("UPDATE "+wechsel.MY_DB_TABLE+" SET "+
                            "name = '"+KfzName.getText().toString()+"', "+
                        "model = '"+KfzModel.getText().toString()+"', "+
                        "bemerkungen ='"+KfzBemerkungen.getText().toString()+"', "+
                        "kraftstoffart ='"+i+"', "+
                        "tankinhalt = '"+KfzTankinhalt.getText().toString()+"' "+
                        "WHERE _id = "+l+";"); 
                }
//Neues KFZ in Datenbank speichern (INSERT)             
                else
                {                   
                    myDB.execSQL("INSERT INTO "+wechsel.MY_DB_TABLE+"name,"+ 
                                                                       "model,"+ 
                                                                       "bemerkungen,"+ 
                                                                       "kraftstoffart,"+ 
                                                                       "tankinhalt) "
                            +"VALUES ('"+KfzName.getText().toString()+"',"+
                            "'"+KfzModel.getText().toString()+"',"+
                            "'"+KfzBemerkungen.getText().toString()+"',"+
                            "'"+i+"',"+"'"+
                                               KfzTankinhalt.getText().toString()+"');");
                }
                finish();
                return true;    
            }
            else
            {
                Toast toast = Toast.makeText(this, "Bitte geben Sie einen Namen für das Fahrzeug ein!", 
                                                                   Toast.LENGTH_SHORT);
                toast.show();
            }
        }
        return false;
    }
}

1 个答案:

答案 0 :(得分:2)

看起来你在名字字段前面的INSERT语句中缺少一个开头语:

                myDB.execSQL("INSERT INTO "+wechsel.MY_DB_TABLE+" (name,"+