-1

Hi I am trying to insert values in my sqlite database but i get "unrecognized token" for the last value exception for byte array. here is code:

 public void insertImage(String userName, String userMob, String meterReading, String readingAddress, String readingRemark, String readingDate , byte[] imageBytes) {
        try {
            mDb.execSQL("INSERT INTO " + IMAGES_TABLE +"(" + USER_NAME + ", " + USER_MOB + ", " + METER_READING_TEXT + ", " + READING_REMARKS + ", " + READING_DATE + ", " + IMAGE + ")" +
                    " VALUES (" + userName + ", " + userMob + ", " + meterReading + ", " + readingAddress + ", " + readingRemark + ", " + readingDate + ", " + imageBytes + ");");
        }
        catch (Exception ex){
            ex.printStackTrace();
            Log.e("-----","dasdasdas");
        }
        }
3
  • 3
    Use parameterized queries. That way, you won't have problems like this. Commented Feb 26, 2017 at 19:08
  • learn this stackoverflow.com/questions/1324641/… Commented Feb 26, 2017 at 19:09
  • Strings must be quoted in SQL. Commented Feb 27, 2017 at 7:57

1 Answer 1

0

seems you have 6 entry in into clause but 7 in values

try {
        mDb.execSQL("INSERT INTO " + IMAGES_TABLE + 
          "(" + USER_NAME + ", " +
           USER_MOB + ", " + 
           METER_READING_TEXT + ", " + 
           READING_REMARKS + ", " + 
           READING_DATE + ", " + 
           IMAGE + ")" +
          " VALUES (" + userName + ", " +
           userMob + ", " + 
           meterReading + ", " + 
           readingAddress + ", " + 
           readingRemark + ", " + 
           readingDate + ", " + 
           imageBytes + ");");
    }

the number of element in both clause must match

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

1 Comment

why downvote ... could this is not the only error but is a valid suggestio for code provided by op

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.