I am using below code to fetch an sqlite record in my android app. This code fetches numeric values, but doesn’t fetch alphanumeric values.
Eg: When “tempno” is 2, the record is fetched, but it doesn’t fetch the record when “tempno” is 2A.
All the variables I’ve used are of “String” data type.
public Map<String, Object> getDetails(String tempno) throws SQLException{
Map<String, Object> map = new HashMap<String, Object>();
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {SOURCE, DESTINATION, ROUTELENGTH, NOTE}, ROUTENO + "=" + tempno, null, null, null, null, null);
Am calling below code from another class.
Please let me know where I am going wrong.
Map<String, Object> temp = dbAdapt.getDetails(tempno);
Below is the error in Logcat
09-26 18:42:52.108: E/AndroidRuntime(2363): android.database.sqlite.SQLiteException: unrecognized token: "2A": , while compiling: SELECT DISTINCT source, destination, routelength, note FROM route WHERE routeno=2A
change it to this:
that is a quick&dirty solution but it works. That is not the common way to put values in a sql string.