Nuwan Indika
Nuwan Indika

Reputation: 919

getting sqLiteException when useing getContentResolver().query()

I'm trying to get data from sqlite database.Tried using thiscontext.getContentResolver().query() method and I got following SqlException

near ":23": syntax error (code 1): , while compiling: SELECT wol_wait, mac_addr, _id, address, name, wol_port, user, timeout, pass FROM hosts WHERE (mac_addr=00:23:15:97:ce:a0) ORDER BY name ASC

this is the code that I’m using

Cursor c=context.getContentResolver().query(HostProvider.Hosts.CONTENT_URI,null, Hosts.MAC_ADDR +"=" +String.valueOf(mhost.mac_addr),null,HostProvider.Hosts.NAME + " ASC");

how can I fix this issue?

Upvotes: 0

Views: 77

Answers (1)

laalto
laalto

Reputation: 152827

String literals such as MAC addresses need to be in 'single quotes', or better yet, use ? placeholders and variable binding. Replace

Hosts.MAC_ADDR +"=" +String.valueOf(mhost.mac_addr),null

with

Hosts.MAC_ADDR +"=?", new String[] { String.valueOf(mhost.mac_addr) }

The String.valueOf is possibly not needed.

Upvotes: 2

Related Questions