I'm not sure why I'm not receiving a count from the following code. It seems pretty straight forward, and yes, there is an id of '24' in this table and field. I think the problem resides somehow with the query and I may not be seeing it.
The Java code with the SQLite query will not return a count.
What I've done:
I've copied the concatenated 'countIDs' string value from the variable (i.e. statement below) and executed it manually against SQLite and it returns the correct count.
I've tried passing the statement directly within the "sConn.preparedStatemement(...), bypassing the string variable and it still doesn't return the correct result.
I've double checked the documentation for SQLite COUNT() function queries. (http://www.sqlitetutorial.net/sqlite-count-function/)
I've messed with using and eliminating the 'while' statement and tried different result set functions.
This is the actual Java concatenated string: SELECT COUNT(*) FROM Notes WHERE SourceID = 24
Since you're already using PreparedStatement, you should use it for any user input. Unfortunately table and column names cannot be parameters to a PreparedStatement, but the value should be:
As for the table name and column name (field), you should validate that these are valid. Preferably you fill them in somewhere in code. If not, and they come from user input, you should at least validate they come from a white list, or have the correct format. Otherwise you could end up being visited by little Bobby Tables.