3

I want to put an table content to a string if a listview item is selected.

My actual query

    public Cursor webUrlQuery() {
    String webUrlTmp = "select weburl FROM stations WHERE name=" + "'" + name + "'";
    return database.rawQuery(webUrlTmp, null);
}

works. But if I log it to logcat via

Log.d(TAG, "webUrl = " + webUrlQuery());

or

Log.d(TAG, "webUrl = " + webUrlQuery().toString());

I got something like this:

12-30 23:25:15.828: D/StationsActivity(10576): streamUrl = android.database.sqlite.SQLiteCursor@4132fce0

How can I get an string which I can use? It seems that the method, cursor.toString() dont work.

3 Answers 3

1

It depends on how many results you're expecting. If you only expect one result, you could use something like this:

Cursor result = webUrlQuery();
result.moveToFirst();
String url = result.getString(result.getColumnIndex("weburl"));
Log.d(TAG, "webUrl = " + url);

Good luck!

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. Thanks. Thats exactly what I want!
1

Cursor.toString() is working perfectly fine - it's returning a string representation of the Cursor object. You presumably want Cursor.getString() (and I believe you'll first need to use Cursor.moveToFirst() to point to the first returned row).

Comments

1

Why are you trying to logcat the Cursor object? If you want to print the query, you need to use webUrlTmp.

BTW, you should really consider binding your query parameters.

1 Comment

I have an listview, with certain items (out of my qslite db). If on item is selected, I want to set a string to one db item. In this example above a url. Logcat is only for testing. :) But if I logcat the webUrlTmp is get only null. Why? If I use sqlite on my device (in adb) I got the right url's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.