samedi 2 janvier 2016

SQlite Table not getting created,but DB got created in Android

I'm new to Android Programming and I am kind of lost with the SQLite table creation.So in my app,user enters three values(Intime,OutTime and Date) which should be saved to the table "updatedata" under Record.db Here is my code for that:

public class Inserted_DB{

public static final String dbname="Record" ;
public static final String table="updatedata";
public static final String in="InTime";
public static final String out="OutTime";
public static final String date="Date";
SQLiteDatabase db;
Context ctx;
helper help;

public Inserted_DB(Context ctx)
{
    this.ctx=ctx;
    help=new helper(ctx);
}


private static class helper extends SQLiteOpenHelper
{
    public helper(Context ctx)

    {
        super(ctx,dbname,null,2);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {

       try
       {
           String sql = "create table "+ table  +"(InTime text,OutTime text,Date text)";
           db.execSQL(sql);

       }
       catch(Exception e1)
        {
            e1.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        db.execSQL("DROP TABLE IF EXISTS " + table);
        onCreate(db);
    }
}
 public void update(String In1,String out1,String date1,Context ct)
 {
   db=help.getWritableDatabase();
   ContentValues con=new ContentValues();
   con.put(in,In1);
   con.put(out,out1);
   con.put(date,date1);
   db.insert(table,null,con);
   db.close();
  }}

I am just calling the update function from another class(Update Tracker) and the snippet is below:

            String in_db=txtTime.getText().toString();
            String out_db=txtTime2.getText().toString();
            Inserted_DB db1=new Inserted_DB(getBaseContext());
            db1.update(in_db,out_db,date_db,UpdateTracker.this);

DB getting created but the table is not.I used DDMS File explorer to navigate to the respective path data/data/mypackage.com.myapp/databases and could see the DB created.Using sqlite3 when I query ".databases",its showing the DB name but when I query ".tables" its empty.

Here is the snap for DB getting created

What am I missing?Could you guys help me out to find a solution!

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire