android - Unable to set data into database -


in below code im trying , set data data base during execution im unable set data in data base ...

settingup

mwirelessrouters = walletwirelessrouter.get(getactivity()).getwirelessrouter(uuid); 

ontextchanged listner

 mbasestationname = (edittext) v.findviewbyid(r.id.base_station_name);     mbasestationname.settext(mwirelessrouters.getbasestationname());     mbasestationname.addtextchangedlistener(new textwatcher() {         @override         public void beforetextchanged                 (charsequence s, int start, int count, int after) {          }          @override         public void ontextchanged                 (charsequence s, int start, int before, int count) {            mwirelessrouters.setbasestationname(s.tostring());         }          @override         public void aftertextchanged                 (editable s) {          }     }); 

note:- in above code im trying take base station name user , update in database..there no issue related view

getwirelessrouter(uuid uuid)

 public wirelessrouter getwirelessrouter(uuid id) {     walletcursorwrapper cursor = querywireless(             walletdbschema.wirelessrouter.cols.uuid + " =? "             , new string[]                     {                             id.tostring()                     }     );      try {         if (cursor.getcount() == 0) {             return null;         }          cursor.movetofirst();         return cursor.getwirelessrouter();     } {         cursor.close();     } } 

querywireless

 private walletcursorwrapper querywireless (string whereclause, string[] whereargs) {     cursor cursor = mdatabase.query(             walletdbschema.wirelessrouter.name,             null, // colums - null select colums             whereclause,             whereargs,             null, //groupby             null, //having             null // order      );      return new walletcursorwrapper(cursor); } 

setbasestation

 public void setbasestationname(string basestationname) {     mbasestationname = basestationname; } 

insert()

public void addwireless (wirelessrouter w) {     contentvalues values = getcontentvalues(w);      mdatabase.insert(walletdbschema.wirelessrouter.name, null, values); } 

starting new fragment

 @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid())     {         case r.id.menu_item_new:              wirelessrouter wirelessrouter = new wirelessrouter();             walletwirelessrouter.get(getactivity()).addwireless(wirelessrouter);             intent intent = wirelessrouterpageractivity                     .newintent(getactivity(), wirelessrouter.getuuid());             startactivity(intent);             return true;           default:             return super.onoptionsitemselected(item);     }  } 

note:-i'm inserting empty string data database while creating fragment

update database

 public void updatewireless(wirelessrouter wirelessrouter) {     string uuidstring = wirelessrouter.getuuid().tostring();     contentvalues values = getcontentvalues(wirelessrouter);      mdatabase.update(walletdbschema.wirelessrouter.name, values,             walletdbschema.wirelessrouter.cols.uuid + " =?"             , new string[]{uuidstring}); } 

writable datbase

 public walletwirelessrouter (context context) {     mcontext = context.getapplicationcontext();     mdatabase = new walletbasehelper(mcontext)             .getwritabledatabase(); } 

if need more data please let me know

you need in transaction (and commit it) if want values saved on completion.

sqlitedatabase db = this.getwritabledatabase(); db.begintransaction() 

...insert, update, delete, etc

if (ok) {    db.settransactionsucessful(); } db.endtransaction(); db.close(); 

this always works me.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -