hi....i am trying to create two tables in single database.. but it is
giving an error while inserting data in second table  error is  =
there is no such table Atten .. that means 2nd table Atten is not
created.. I have searched a lot for this.. but i am not getting any
good solution.. .. I am posting my code below.. whether  i am missing
something.. or any error plz any suggestions are welcome..



public class helper {

        public static final String KEY_ROW_ID = "_id";
        public static final String KEY_DESG_ID = "desig_id";
        public static final String KEY_RB_ID = "rb_id";
        public static String KEY_NAME = "empname";
    public static final String KEY_PASSWD = "passwd";
    public static final String KEY_GENDER = "gender";
    public static final String KEY_DESIGNATION = "designation";

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "emp_info";
    private static final String DATABASE_TABLE = "emp";
    private static final int DATABASE_VERSION = 1;

    private static final String DB_NEW_TABLE = "Atten";



    public static final String KEY_ID = "_id";
    public static final String KEY_LG_ID = "LG_id";

    public static final String KEY_ENAME="ename";
    public static final String KEY_DATE="date";
    public static final String KEY_DAYCOUNT = "daycount";







    private static final String DATABASE_CREATE =
        "create table emp ( _id integer primary key
autoincrement,desig_id integer not null,rb_id integer not null,empname
text not null,passwd text not null,gender text not null,designation
text not null);";


    private static final String DB_CREATE =
                     "create table Atten( _id integer primary key
autoincrement,FOREIGN KEY(LG_id) REFERENCES emp(_id) ,ename text not
null, Date date , integer daycount not null);";


    private final Context context;

    private DatabaseHelper DBHelper;

    public SQLiteDatabase db;



    public helper(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)
  {

       try


       {
           db.execSQL(DB_CREATE);
           db.execSQL(DATABASE_CREATE);

       }


       catch(SQLiteException e) {
           Log.e(TAG,""+e.getMessage());
       }



  }

        @Override
       public void onUpgrade(SQLiteDatabase db, int oldVersion,
                                int newVersion)
                               {
                                    Log.w(TAG, "Upgrading database from version 
" +
oldVersion
                                            + " to "
                                           + newVersion + ", which will destroy 
all
old data");

                                   db.execSQL("DROP TABLE IF EXISTS emp");

                                   db.execSQL("DROP TABLE IF EXISTS Atten");
                                   onCreate(db);
                               }

    }

    //---opens the database---
    public helper open() throws SQLException
    {
        //  Log.e(TAG,"in open...");

        db = DBHelper.getWritableDatabase();
        return this;
    }

    //---closes the data---
    public void close()
    {
        DBHelper.close();
    }






    //---insert a employee into the data---
    public boolean insertEmployee(int desig_id,int rb_id ,String
uname, String pwd, String gender,String desig)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_DESG_ID,desig_id);
        initialValues.put(KEY_RB_ID, rb_id);
        initialValues.put(KEY_NAME, uname);
        initialValues.put(KEY_PASSWD, pwd);
        initialValues.put(KEY_GENDER, gender);
        initialValues.put(KEY_DESIGNATION  , desig);
        db.insert(DATABASE_TABLE, null, initialValues);
        return true;

    }


    public boolean  insertAtten(int Empid,String Name, java.sql.Date
dt , int daycnt)

      {


          ContentValues cv = new ContentValues();
         cv.put(KEY_LG_ID,Empid);
          cv.put(KEY_ENAME, Name);
          cv.put(KEY_DATE,  String.valueOf(dt));
          cv.put(KEY_DAYCOUNT,daycnt);

          db.insert( DB_NEW_TABLE, null,cv);


          return true;



      }



}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to