-2

Hi I am very new to android please help me i am not able to solve this error

Here is logcat error

    android.database.sqlite.SQLiteException: no such column: datename (code 1):
   , while compiling: select productinserted from mbudgettable where datename=?

THIS IS THE LINE WHERE SHOWING THE ERROR IN THE LOGCAT-

www.monthlybudget.suyash.DatabaseHandler.tproduct(DatabaseHandler.java:152)

LINES IN THE DATABASE ACTIVITY-

151 String query = "select "+productinserted+" from " + tablename + " where datename="; line 152 Cursor cursor = db.rawQuery(query, new String[] {sto});

THIS IS HOW I CREATED DATABASE-

      @Override
      public void onCreate(SQLiteDatabase db) {

     String CREATE_TABLE = "CREATE TABLE " + tablename + "("+KEY_ID + "INTEGER PRIMARY KEY,
      " + budgetinserted +" double, " +productinserted + " TEXT, " +amountinserted + " double,
     " +todayproductinserted + " TEXT,"  + todayamountinserted + " double, " + monthlyproductinserted + " string,
      " +monthlyamountinserted + " double, " + yearlybudgetinserted + "double, " + datename + "LONG, " + monthyear + "LONG);";

    db.execSQL(CREATE_TABLE);

   }

   @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + tablename);

    onCreate(db);


}

PLEASE HELP ME GUYS-

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

4

Add spaces between column names and column types. Change

yearlybudgetinserted + "double, " + datename + "LONG, " + monthyear + "LONG);"

to

yearlybudgetinserted + " double, " + datename + " LONG, " + monthyear + " LONG);"

After modifying the schema like this, you can uninstall your app once so that the database gets recreated.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • Now I am getting this error //logcat android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: select productinserted from mbudgettable wheredatename= String query = "select "+productinserted+" from " + tablename + " where" + datename +"="+sto; Cursor cursor = db.rawQuery(query,new String[]{sto}); – suyash saurabh May 02 '17 at 19:38
  • 1
    You need space after `where` too. – laalto May 02 '17 at 19:43
1

In your Create Table query, the 'datename' is a variable. But in your select query, it is directly used as a string(inside quotes) !.

"select "+productinserted+" from " + tablename + " where datename=";

Instead use the following select query.

"select "+productinserted+" from " + tablename + " where " + datename +"=";

Gokul Raj Kumar
  • 335
  • 2
  • 9
  • I am Getting this error after changing the queryCaused by: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: select productinserted from mbudgettable wheredatename= – suyash saurabh May 02 '17 at 19:34