I have create a class DatabaseInterface which will be used for Sqlite operations.
DatabaseInterface.onCreate() (where I have created a table) Method is not getting executed when i create an object of this class.
I have created object of DatabaseInterface in another class FirstTimeActivity
public class FirstTimeActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DatabaseInterface db = new DatabaseInterface(this);
}
}
Below is class Definition of DatabaseInteface. The OnCreate() method is not getting executed, so my table is not getting created. The database has already been created.
public class DatabaseInterface extends SQLiteOpenHelper{
private static String DB_NAME = "SMS_DB";
private static int DB_VERSION = 1;
private String TABLE_NAME = "SENT_ITEMS";
private String COLUMN_ID = "S_NO";
private String COLUMN_MESSAGE = "MESSAGE";
private String COLUMN_DATETIME = "DATE_TIME";
//creates the database
public DatabaseInterface(Context context) {
super(context, DB_NAME, null, DB_VERSION);
Log.d("Creating Database: ", "Creating Database");
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d("Creating Table: ", "Creating Table");
String create_table = "CREATE TABLE "+ TABLE_NAME + " ("+ COLUMN_ID +" INTEGER PRIMARY KEY, " + COLUMN_MESSAGE + " TEXT, " + COLUMN_DATETIME + "TEXT NOT NULL); ";
db.execSQL(create_table);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void insertIntoDB(String message)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
//get current date and time
Calendar current_time = Calendar.getInstance();
//current_time.getTime();
String Cure = current_time.toString();
Log.d("Current_Date_time: ", Cure);
values.put(COLUMN_MESSAGE, message);
values.put(COLUMN_DATETIME, "ad");
db.insert("TEST", null, values);
db.close(); // Closing database connection
}
};