Reputation: 520
i am having a DB connection in my application.i used below code
db = openOrCreateDatabase(
"highscore.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
db.setVersion(1);
final String CREATE_TABLE_HIGHSCORE =
"CREATE TABLE HIGHSCOREDETAILS ("
+ "NAME TEXT,"
+ "SCORE INTEGER);";
db.execSQL(CREATE_TABLE_HIGHSCORE);
but when the second time i am running the app it crashes...the error showing is
06-13 16:35:51.552: ERROR/AndroidRuntime(1398): Caused by: android.database.sqlite.SQLiteException: table HIGHSCOREDETAILS already exists: CREATE TABLE HIGHSCOREDETAILS (NAME TEXT,SCORE INTEGER);
And i also want to retrieve the greatest value in the score column.This is the first time i am working with DB connection...so please help me...thanks in advance
Upvotes: 1
Views: 259
Reputation: 4111
Exception tells you that table HIGHSCOREDETAILS already exists. If you update DB, check if this table deleted previously
Upvotes: 0
Reputation: 12356
Change your query to:
CREATE TABLE IF NOT EXISTS HIGHSCOREDETAILS (
To get the highest value use this:
SELECT MAX(SCORE) FROM HIGHSCOREDETAILS
Upvotes: 1