Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:48:51+00:00 2026-05-29T11:48:51+00:00

am doing a small project to store the employee details and modify it. i

  • 0

am doing a small project to store the employee details and modify it. i was successful until i add the employee id column named EmpID. And the data is not inserting in table showing an error:

 android.database.sqlite.SQLiteException: table Employees has no column named EmpID:
 while compiling: INSERT INTO Employees(Mobile, Age, EmpID, Dept, EmployeeName) VALUES(?, ?, ?, ?, ?);

Am not able to get what the problem is.. Here is my databasehelper code for creating the database table.. Can anyone please help me..

public class DatabaseHelper extends SQLiteOpenHelper {

   static final String dbName="demoDB";
   static final String employeeTable="Employees";
   static final String colID="EmployeeID";
   static final String colName="EmployeeName";
   static final String colempId="EmpID";
   static final String colAge="Age";
   static final String colMobile="Mobile";
   static final String colDept="Dept";  
   static final String deptTable="Dept";
   static final String colDeptID="DeptID";
   static final String colDeptName="DeptName";
   static final String viewEmps="ViewEmps"; 

       public DatabaseHelper(Context context) {
            super(context, dbName, null,33);                        
            // TODO Auto-generated constructor stub
      }

     @Override
        public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub      
        db.execSQL("CREATE TABLE "+deptTable+" ("+colDeptID+ " INTEGER PRIMARY KEY , "+
            colDeptName+ " TEXT)");     
        db.execSQL("CREATE TABLE "+employeeTable+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+colName+" TEXT,"+colempId+" TEXT, "+
        colAge+" Integer,"+colMobile+" TEXT, "+colDept+" INTEGER NOT NULL ,FOREIGN KEY ("+colDept+") REFERENCES "+deptTable+" ("+colDeptID+"));");      
        db.execSQL("CREATE TRIGGER fk_empdept_deptid " +
            " BEFORE INSERT "+
            " ON "+employeeTable+

            " FOR EACH ROW BEGIN"+
            " SELECT CASE WHEN ((SELECT "+colDeptID+" FROM "+deptTable+" WHERE "+colDeptID+"=new."+colDept+" ) IS NULL)"+
            " THEN RAISE (ABORT,'Foreign Key Violation') END;"+
            "  END;");

    db.execSQL("CREATE VIEW "+viewEmps+
            " AS SELECT "+employeeTable+"."+colID+" AS _id,"+
            " "+employeeTable+"."+colName+","+
            " "+employeeTable+"."+colempId+","+
            " "+employeeTable+"."+colAge+","+
            " "+employeeTable+"."+colMobile+","+
            " "+deptTable+"."+colDeptName+""+
            " FROM "+employeeTable+" JOIN "+deptTable+
            " ON "+employeeTable+"."+colDept+" ="+deptTable+"."+colDeptID
            );
    //Inserts pre-defined departments
    InsertDepts(db);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub      
    db.execSQL("DROP TABLE IF EXISTS "+employeeTable);
    db.execSQL("DROP TABLE IF EXISTS "+deptTable);      
    db.execSQL("DROP TRIGGER IF EXISTS dept_id_trigger");
    db.execSQL("DROP TRIGGER IF EXISTS dept_id_trigger22");
    db.execSQL("DROP TRIGGER IF EXISTS fk_empdept_deptid");
    db.execSQL("DROP VIEW IF EXISTS "+viewEmps);
    onCreate(db);
}

 void AddEmployee(Employee emp)
{        
    SQLiteDatabase db= this.getWritableDatabase();      
    ContentValues cv=new ContentValues();       
    cv.put(colName, emp.getName());
    cv.put(colempId, emp.getempID());
    cv.put(colAge, emp.getAge());
    cv.put(colMobile, emp.getMobile());
    cv.put(colDept, emp.getDept());
    //cv.put(colDept,2);

    db.insert(employeeTable, colName, cv);
    db.close();     

}

 int getEmployeeCount()
 {
    SQLiteDatabase db=this.getWritableDatabase();
    Cursor cur= db.rawQuery("Select * from "+employeeTable, null);
    int x= cur.getCount();
    cur.close();
    return x;
 }

 Cursor getAllEmployees()
 {
     SQLiteDatabase db=this.getWritableDatabase();       
     //Cursor cur= db.rawQuery("Select "+colID+" as _id , "+colName+", "+colAge+" from "+employeeTable, new String [] {});
     Cursor cur= db.rawQuery("SELECT * FROM "+viewEmps,null);
     return cur;         
 }

 Cursor getAllDepts()
 {
     SQLiteDatabase db=this.getReadableDatabase();
     Cursor cur=db.rawQuery("SELECT "+colDeptID+" as _id, "+colDeptName+" from "+deptTable,new String [] {});        
     return cur;
 }

 void InsertDepts(SQLiteDatabase db)
 {
     ContentValues cv=new ContentValues();
        cv.put(colDeptID, 1);
        cv.put(colDeptName, "Sales");
        db.insert(deptTable, colDeptID, cv);
        cv.put(colDeptID, 2);
        cv.put(colDeptName, "IT");
        db.insert(deptTable, colDeptID, cv);
        cv.put(colDeptID, 3);
        cv.put(colDeptName, "HR");
        db.insert(deptTable, colDeptID, cv);
        db.insert(deptTable, colDeptID, cv);

 }

 public String GetDept(int ID)
 {
     SQLiteDatabase db=this.getReadableDatabase();       
     String[] params=new String[]{String.valueOf(ID)};
     Cursor c=db.rawQuery("SELECT "+colDeptName+" FROM"+ deptTable+" WHERE "+colDeptID+"=?",params);
     c.moveToFirst();
     int index= c.getColumnIndex(colDeptName);
     return c.getString(index);
 }

 public Cursor getEmpByDept(String Dept)
 {
     SQLiteDatabase db=this.getReadableDatabase();
     String [] columns=new String[]{"_id",colName,colempId,colAge,colMobile,colDeptName};
     Cursor c=db.query(viewEmps, columns, colDeptName+"=?", new String[]{Dept}, null, null, null);
     return c;
 }

 public int GetDeptID(String Dept)
 {
     SQLiteDatabase db=this.getReadableDatabase();
     Cursor c=db.query(deptTable, new String[]{colDeptID+" as _id",colDeptName},colDeptName+"=?", new String[]{Dept}, null, null, null);
     //Cursor c=db.rawQuery("SELECT "+colDeptID+" as _id FROM "+deptTable+" WHERE "+colDeptName+"=?", new String []{Dept});
     c.moveToFirst();
     return c.getInt(c.getColumnIndex("_id"));

     }

 public int UpdateEmp(Employee emp)
 {
     SQLiteDatabase db=this.getWritableDatabase();
     ContentValues cv=new ContentValues();
     cv.put(colName, emp.getName());
     cv.put(colempId, emp.getempID());
     cv.put(colAge, emp.getAge());
     cv.put(colMobile, emp.getMobile());
     cv.put(colDept, emp.getDept());
     return db.update(employeeTable, cv, colID+"=?", new String []{String.valueOf(emp.getID())});

 }

 public void DeleteEmp(Employee emp)
 {
     SQLiteDatabase db=this.getWritableDatabase();
     db.delete(employeeTable,colID+"=?", new String [] {String.valueOf(emp.getID())});
     db.close();

 }
}

and the error message am getting when i click on view page is..

android.database.sqlite.sqlexception: no such column EmpID:, while compiling: select_id, EmployeeName, EmpID, Age, Mobile,DeptName FROM ViewEmps WHERE DeptName=?

Thanks in Advance….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:48:53+00:00Added an answer on May 29, 2026 at 11:48 am

    Your code looks fine to me. You may have included the EmpID recently to the table & not upgraded the database version OR you may have changed the defenition of EmpID so try to increase the DataBase-Version here:

    public DatabaseHelper(Context context) 
    {
        super(context, dbName, null,33);
    
        // TODO Auto-generated constructor stub
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a small project using JPA. I need to insert the employee
I am currently doing a small data structures project, and I am trying to
I am doing small project on grails. I am trying to add networking concepts
Hi i am doing a small project in C#, and i need to know
I have a small project I am doing in Python using web.py. It's a
I have a small- to medium-size project that I am doing for my software
Im doing a small project in C++ in LINUX PLATFORM.i need to search 10
I'm doing a small project including a connection to sqlite. I write to two
Sorry if this is a stupid noob question. I'm doing a very small project
Doing a small project I have received some Java code that I should rewrite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.