patrick1980 patrick1980 - 1 year ago 81
Java Question

Try to convert Arraylist<LatLng> to string before insert to database

I try to insert my

ArrayList<LatLng> list1
with a lot of values like this:
to table in database MySQL, exacly to 1 column, something like this:

row 1 (99.9999999,99.9999999)
row 2 (99.9999999,99.9999999)
row 3 (99.9999999,99.9999999)

... all to 1 column.

In my opinion, currently i have a good method for this:

String sql = "INSERT INTO table1 VALUES(";
for(String s : list1) {
sql = sql+"'"+s+"'";
sql = sql+")";

but Android Studio underlines
String s
and says:

Incompatible types
Found: java.lang.String

In my opinion, Android Studio trying to say me: you need to convert all values from
ArrayList<LatLng> list1

Is it possible to convert all values from my
in one method ?

Answer Source

You can convert your data to string the following way:

for(LatLng s : list1)
    String sql = "INSERT INTO table1 VALUES('"+s+"');

That is, you don't have to do anything specific to convert it. I'm assuming you have the method toString() implemented in your LatLng class to give objects of LatLng type a meaningful string representation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download