我需要更新数据库中的选定列,但是我无法获取更新的数据。用户单击下一步按钮后,数据应该会更新。表中总共需要更新 12 个字段。
注意:dba 是 DBAdapter,即数据库,myDB 是 SQLiteDatabase
nxt = (Button)findViewById(R.id.btn_nxt);
nxt.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String b1=t1.getText().toString();
String b2=goal_website_trying_to_achieve_edttxt.getText().toString();
String b3=communicate_edttxt.getText().toString();
String b4=success_look_like_edttxt.getText().toString();
String b5=usp_insights_edttxt.getText().toString();
String b6=act_edttxt.getText().toString();
String b7=market_edttxt.getText().toString();
String b8=your_current_website_www_edttxt.getText().toString();
String b9=your_current_website_good_edttxt.getText().toString();
String b10=your_current_website_bad_edttxt.getText().toString();
String b11=your_current_website_type_edttxt.getText().toString();
String b12=your_current_website_update_edttxt.getText().toString();
String b13=your_current_website_supporting_edttxt.getText().toString();
if(!validatescreen2()){
return;
}
else{
dba.open();
String updatequery = "UPDATE "+ DBAdapter.DATABASE_TABLE+ " SET ";
updatequery = updatequery + " KEY_MESSAGE_1 = " + b1 +"WHERE" +"_id"+mRowId +",";
updatequery = updatequery + " KEY_MESSAGE_2 = " + b2 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_MESSAGE_3 = " + b3 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_MESSAGE_4 = " + b4 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_MESSAGE_5 = " + b5 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_MESSAGE_6 = " + b6 + "WHERE" +"_id"+mRowId +"',";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_1 = " + b7 + "WHERE" +"_id"+mRowId +",";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_2 = " + b8 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_3 = " + b9 +"WHERE" +"_id"+mRowId + ",";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_TYPE = " + b10 + "WHERE" +"_id"+mRowId +",";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_NEED = " + b11 + "WHERE" +"_id"+mRowId +",";
updatequery = updatequery + " KEY_YOUR_CURRENT_WEBSITE_OTHER = " + b12 + "WHERE" +"_id"+mRowId ;
try{
myDB.execSQL(updatequery);
}catch(Exception e){
Log("Caught while writing response" + e.getLocalizedMessage());
}finally{
if(myDB != null)myDB.close();
}
showDialog(DIALOG_ID);
dba.close();
}
}
});
所做的更改
String updatequery = "UPDATE"+ DBAdapter.DATABASE_TABLE+ " SET "+ DBAdapter.KEY_MESSAGE_1 +"= "+ b1 +
DBAdapter.KEY_MESSAGE_2 +"= "+ b2 +
DBAdapter.KEY_MESSAGE_3 +"= "+ b3 +
DBAdapter.KEY_MESSAGE_4 +"= "+ b4 +
DBAdapter.KEY_MESSAGE_5 +"= "+ b5 +
DBAdapter.KEY_MESSAGE_6 +"= "+ b6+
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_1 +"= "+ b7 +
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_2 +"= "+ b8 +
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_3 +"= "+ b9+
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_TYPE +"= "+ b10 +
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_NEED +"= "+ b11 +
DBAdapter.KEY_YOUR_CURRENT_WEBSITE_OTHER +"= " + b12 + "WHERE" + DBAdapter.KEY_ROWID + "=" + mRowId ;
logcat error file
01-30 12:02:24.136: W/System.err(2645): java.lang.NullPointerException
01-30 12:02:24.136: W/System.err(2645): at com.example.sales.Newform_Screen2$3.onClick(Newform_Screen2.java:165)
01-30 12:02:24.136: W/System.err(2645): at android.view.View.performClick(View.java:4084)
01-30 12:02:24.136: W/System.err(2645): at android.view.View$PerformClick.run(View.java:16966)
01-30 12:02:24.136: W/System.err(2645): at android.os.Handler.handleCallback(Handler.java:615)
01-30 12:02:24.136: W/System.err(2645): at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 12:02:24.136: W/System.err(2645): at android.os.Looper.loop(Looper.java:137)
01-30 12:02:24.136: W/System.err(2645): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-30 12:02:24.136: W/System.err(2645): at java.lang.reflect.Method.invokeNative(Native Method)