I am trying to create a table in the Android SQLite database. But execSQLite method does not work in the on create method. It gives me the message-
Non-static method 'execSQL' cannot be a reference from a static context
But the method I am calling from is a non-static method. The method is given below.
public void onCreate(SQLiteDatabase sqLiteDatabase) {
SQLiteDatabase.execSQL();
}
Here is my full java code:
package com.sarsinetvarneshon.basicdb;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by Sarsinet Varneshon on 23-Apr-18.
*/
public class EmployeeDatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "db_employee";
public static final int VERSION = 1;
public static final String EMPLOYEE_TABLE_NAME = "tbl_employee";
public static final String EMPLOYEE_COL_ID = "id";
public static final String EMPLOYEE_COL_NAME = "name";
public static final String EMPLOYEE_COL_AGE = "age";
public static final String EMPLOYEE_COL_DEPT = "dept";
public static final String CREATE_TABLE_EMPLOYEE = " CREATE TABLE "+ EMPLOYEE_TABLE_NAME+
"("+EMPLOYEE_COL_ID+ " INTEGER PRIMARY KEY, "+
EMPLOYEE_COL_NAME+ " TEXT, "+
EMPLOYEE_COL_AGE+ " INT, "+
EMPLOYEE_COL_DEPT+ " TEXT)";
public EmployeeDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
SQLiteDatabase.execSQL();
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}