lundi 29 décembre 2014

Android Application closes while setting up database

Please i am trying to create an application with a database and i have tried creating the database with sqlite, the code seems right to me but when i try to run it using the emulator. the application closes, i am using android studio for my development. there's nothing important in the xml layout file. But i intend to populate the database from to be designed with the database fields. i'll also appreciate any recommendation on how to go about it


this is the database java file


public class DatabaseActivity extends Activity {



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.db_page);

/*db.execSQL("INSERT INTO MyTable VALUES('Adetoro', 'Samuel', 21);");
db.execSQL("INSERT INTO MyTable VALUES('Adetoro', 'Glory', 19);");*/

SQLiteDatabase db = openOrCreateDatabase("CalendarDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS 'eventDetails' (\n" +
" 'event_ID' int(3) NOT NULL AUTO_INCREMENT,\n" +
" 'EventTitle' varchar(35) DEFAULT NULL,\n" +
" 'StartTime' time(6) DEFAULT NULL,\n" +
" 'StartDate' date DEFAULT NULL,\n" +
" 'FinishTime' time(6) DEFAULT NULL,\n" +
" 'FinishDate' date DEFAULT NULL,\n" +
" 'EventAttributes' varchar(200) DEFAULT NULL,\n" +
" 'SetupTime' timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n" +
" PRIMARY KEY ('event_ID'),\n" +
" UNIQUE KEY 'EventTitle' ('EventTitle')\n" +
");");

db.execSQL("INSERT INTO 'calendar' ('event_ID', 'EventTitle', 'StartTime', 'StartDate', 'FinishTime', 'FinishDate', 'EventAttributes', 'SetupTime') VALUES\n" +
"(1, 'Project Defence', '05:20:21.000000', '2014-01-29', '12:20:21.000000', '2014-12-29', NULL, '2014-12-29 11:20:21'),\n" +
"(2, 'New Year''s Eve', '08:21:07.000000', '2014-05-29', '12:21:07.000000', '2015-04-29', NULL, '2014-12-29 11:21:07');");

db.close();


}


Aucun commentaire:

Enregistrer un commentaire