0

I have an update syntax and when I call it is not doing what it suppose to do. I don't get an error it just doesnt update the table itself. I have other SQL syntax that I call like insert, select, and delete and all are working. I use the similar format. I am not sure if update has a different way compare to the other syntax. I been liking the way that a SQL syntax is stored in a String variable because it gives me the sense how it looks in the database when doing such syntax. Could someone please help me with this?

 //UPDATE new SETTING into duel setting Table  using sql statement
                          public void addnewsettingDUELSETTING(){
                              String SQLADD2DUELSETTING = "UPDATE " +YAOMySQLiteHelper.TABLE_DUEL_SETTING +
                                                          " SET " + YAOMySQLiteHelper.COLUMNds_ID + " = '" + "1" + "' ,"+ 
                                                          YAOMySQLiteHelper.COLUMNds_ME + " = '"+ DuelSettingMenu.xsp1  +  "' , " +
                                                          YAOMySQLiteHelper.COLUMNds_OPPONENT + " = '"+ DuelSettingMenu.xsp2  +  "' , " +
                                                          YAOMySQLiteHelper.COLUMNds_LIFE_POINT + " = '"+ DuelSettingMenu.xsp3  +  "' , " +
                                                          YAOMySQLiteHelper.COLUMNds_GAME_TIMER + " = '"+ DuelSettingMenu.xsp4  +  "' , " +
                                                          YAOMySQLiteHelper.COLUMNds_CALCULATOR_LAYOUT + " = '"+ DuelSettingMenu.xsp5 + "'" +
                                                          " WHERE " +YAOMySQLiteHelper.COLUMNds_ID + " = " + "'1'" ;


                              database.execSQL(SQLADD2DUELSETTING);

                          }

2 Answers2

2

//Here is some simple sample code for update

//First declare this

private DatabaseAppHelper dbhelper;
private SQLiteDatabase db;

//initialize the following

dbhelper=new DatabaseAppHelper(this);
        db=dbhelper.getWritableDatabase();

//updation code

 ContentValues values= new ContentValues();
                values.put(DatabaseAppHelper.KEY_PEDNAME, ped_name);
                values.put(DatabaseAppHelper.KEY_PEDPHONE, ped_phone);
                values.put(DatabaseAppHelper.KEY_PEDLOCATION, ped_location);
                values.put(DatabaseAppHelper.KEY_PEDEMAIL, ped_emailid);
                db.update(DatabaseAppHelper.TABLE_NAME, values,  DatabaseAppHelper.KEY_ID + "=" + msysprefs.getid(), null);

//put ur id instead of msysprefs.getid().msysprefs.getid() is a function in my shared preference.

I think Your mistake is you have written "1" instead of 1.I think it would be " WHERE " +YAOMySQLiteHelper.COLUMNds_ID + " = " + 1;

Mainak Mukherjee
  • 782
  • 1
  • 6
  • 10
0

I think you are doing wrong at the end of the query with "'1'" It should be 1. Anyway I haven't tried queries statements so much because android has predefined methods to do that. Take a look at this enter link description here

Community
  • 1
  • 1
Sar
  • 550
  • 4
  • 18