using SQLite database for the very first time in android. how? -


after installing android sdk , eclipse first time using sqlite. should need settings or register in manifest.xml?

i unable use sqlite database showing errors like

sqlite database db; sqlite in underlines in red , stating

(multiple markers @ line - sqlite cannot resolved type - syntax error on token "sqlite", invalid modifiers)

and also

sqlite cannot resolved type , giving suggestions as-

create class sqlite create interface sqlite , other 9 suggestions.

what shud do?

you need have databasehelper class make easy understand. can manipulate according needs.

import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log;  public class databasehandler {      public static final string key_rowid = "_id";     public static final string key_proname = "proname";     public static final string key_procost = "procost";     private static final string tag = "dbadapter";     //private static final string tag = dbadapter.class.getsimplename();      private static final string database_name = "product";     private static final string database_table = "productdet";     private static final int database_version = 1;      private static final string database_create =         "create table productdet (_id integer primary key autoincrement, "+ "proname varchar ,"+ "procost varchar);";     private final context context;      private databasehelper dbhelper;    private sqlitedatabase db;     public databasehandler(context ctx)     {         this.context = ctx;         dbhelper = new databasehelper(context);    }     private static class databasehelper extends sqliteopenhelper     {        databasehelper(context context)         {             super(context, database_name, null, database_version);        }         @override        public void oncreate(sqlitedatabase db)         {            db.execsql(database_create);        }         @override        public void onupgrade(sqlitedatabase db, int oldversion,         int newversion)         {             log.w(tag, "upgrading database version " + oldversion                     + " "                    + newversion + ", destroy old data");             db.execsql("drop table if exists productdet");            oncreate(db);         }     }          //---opens database---      public databasehandler open() throws sqlexception      {          db = dbhelper.getwritabledatabase();          return this;     }      //---closes database---         public void close()      {         dbhelper.close();     }       //---insert title database---     public long inserttitle(string proname, string procost)      {          contentvalues initialvalues = new contentvalues();          initialvalues.put(key_proname, proname);          initialvalues.put(key_procost, procost);          return db.insert(database_table, null, initialvalues);     }      //---deletes particular title---     public boolean deletetitle(long rowid)      {          return db.delete(database_table, key_rowid +              "=" + rowid, null) > 0;     }      //---retrieves titles---     public cursor getalltitles()      {          return db.query( database_table, new string[] {                key_rowid,                 key_proname,                key_procost,                 },                  null,                  null,                  null, null, null);     }       //---retrieves particular title---     public cursor gettitle(long rowid) throws sqlexception      {         cursor mcursor =             db.query(true, database_table, new string[] {                     key_rowid,                     key_proname,                      key_procost,                      },                      key_rowid + "=" + rowid,                      null,                     null,                      null, null, null                      );         if (mcursor != null) {              mcursor.movetofirst();         }         return mcursor;     }      //---updates title---     public boolean updatetitle(long rowid, string proname,      string procost)      {         contentvalues args = new contentvalues();         args.put(key_proname, proname);         args.put(key_procost, procost);         return db.update(database_table, args,                       key_rowid + "=" + rowid, null) > 0;     }   } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -