android emulator - Problem while creating table with sqLite -


i created 1 demo in android regarding database. while executing facing problem. can 1 please me. here code developed.

package com.android;  import android.app.activity; import android.database.cursor; import android.database.sqlite.*; import android.os.bundle; import android.util.log; import android.widget.textview;  public class databasework extends activity {       public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          string my_database_name="trademarket";         string my_database_table="shares";          string data="database";          sqlitedatabase mydb=null;         try{              mydb=this.openorcreatedatabase(my_database_name,mode_private, null);              mydb.execsql("create table if not exist" + my_database_table + "(lastname varchar,firstname varchar,country varchar,age int(3));");               /* code insert data in databse*/             mydb.execsql("insert into" + my_database_table + "(lastname,firstname,country,age)"+ "values('joshi','anup','india',24);");              mydb.execsql("insert into" + my_database_table + "(lastname,firstname,country,age)"+ "values('jalkotkar','sachin','france',25);");              /*code fetch data database */             cursor c=mydb.rawquery("select * from" + my_database_table ,null);              int lastnameindex=c.getcolumnindex("lastname");             int firstnameindex=c.getcolumnindex("firstname");             int countryindex=c.getcolumnindex("country");             int ageindex=c.getcolumnindex("age");                  c.movetofirst();                 if(c!=null){                          do{                             string firstname=c.getstring(firstnameindex);                             string lastname=c.getstring(lastnameindex);                             string country=c.getstring(countryindex);                             int age=c.getint(ageindex);                             data=data +firstname + "/" + lastname + "/" + country + "/" + age + "\n";                             }while(c.movetonext());                     }                              textview tv = new textview(this);                              tv.settext(data);                              setcontentview(tv);              }catch(exception e) {                 log.e("error", "error", e);                 } {                  if (mydb != null)                   mydb.close();                 }      }//end of oncreate method. }// end of databasework. 

the following code:

mydb.execsql("create table if not exist" + my_database_table + "(lastname,... 

will produce sql this:

create table if not existshares(lastname,... 

likewise:

mydb.execsql("insert into" + my_database_table + "(lastname,... 

will become this:

insert intoshares(lastname,... 

same mydb.rawquery("select * from" + my_database_table.

also note @thelost's answer.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -