1

I am trying to update a table that accepts two parameters (Integer and String) in where clause.

If I write a query that has no problem where I can directly write those in where clause but I am doing this programmatically where Insert method of SQLite in Android need to be passed the values.

Insert accepts only String arguments but I need to pass one String and one Integer, how do I achieve this?

Database.getInstance(getApplicationContext()).getWritableDatabase().update(st.tablename,
 st.update(buy,Buyprice , Sell, Sellprice), (st.column2+" =? and "+ st.column3+" =? "),(new 
String[] {getdate,name}));

In above command getdate is Integer and name is String but it is giving the error:

Type mismatch: cannot convert from Integer to String

halfer
  • 19,824
  • 17
  • 99
  • 186
Siva
  • 9,043
  • 12
  • 40
  • 63

2 Answers2

3

How you can keep intenger into String array? This is not possible.

So you need to typecast the integer.

like

String[] {String.valueOf(getdate),name}

It will be handled to check your integer column. No worry about that.

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • Thanks for your reply...but column is Integer how can it compare String value and will the query accepts comparing integer with a string in where clause – Siva Nov 11 '14 at 09:58
  • You pass where values into string[], and those will be handled internally by sqlite. – Pankaj Kumar Nov 11 '14 at 10:00
  • Thanks for your answer.. will try and accept as answered – Siva Nov 11 '14 at 10:09
0

Is getdate the primitive int or the Object Integer? One simple way of converting an int to String is simply adding "" before the int. {"" + getdate, name}

If you are using the Object Integer use .toString()1

Community
  • 1
  • 1
kotlinski
  • 331
  • 2
  • 6