0

Trying to get the value of the "value" column where the "option" column is = "lastclick" in sqlite for my android app.

Here is my code for the function:

public String getLastClick() { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT value FROM config where option='lastclick'", null); cursor.moveToFirst(); return cursor.getString(0); } 

It does not seem to be working correctly... I am using the following code for a conditional statement and it doesn't ever recognize the string as being 0 even when I first install the app on the VD, my onCreate function inserts a row with a "lastclick" value of "0" into the database.

Anyway here is that code:

 DatabaseHandler db = new DatabaseHandler(this); String lastClick = db.getLastClick(); // check if its the first time they've ever clicked if (lastClick != "0") { String millis = String.valueOf(Long.parseLong(dateString) - Long.parseLong(lastClick)); db.insertRecord(millis); } 

"option" and "value" are both varchar's.

1
  • And, do remember to close your Cursors. Putting a try { return cursor.moveToNext() ? cursor.getString(0) : null; } finally { cursor.close();} is easy and should be part of basic hygiene. Commented May 27, 2012 at 8:26

1 Answer 1

2

The correct way to compare Strings is to use the equals method, so instead of :

if (lastClick != "0") { 

write:

if (!lastClick.equals("0")) { 
Sign up to request clarification or add additional context in comments.

1 Comment

wouldnt it be if (!lastClick.equals("0")) { ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.