0

I have a table table1 in my database. This table have a column column1 set to varchar(20)

I have all my data in ArrayList<LatLng> list1

Now i trying to insert my list1 to column1 but my idea didn't work:

 try
        {
            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection(url1, user1, pass1);

            stmt = conn.createStatement();

            String sql = "INSERT INTO table1 VALUES(list1)";

            stmt.executeUpdate(sql);



        }catch(SQLException se){

            se.printStackTrace();
        }catch(Exception e){

            e.printStackTrace();
        }finally{

            try{
                if(stmt!=null)
                    conn.close();
            }catch(SQLException se){
            }
            try{
                if(conn!=null)
                    conn.close();
            }catch(SQLException se){
                se.printStackTrace();
            }
        }

What is wrong here?

patrick1980
  • 91
  • 1
  • 8
  • OP reposted better question at: http://stackoverflow.com/questions/40442503/try-to-convert-arraylistlatlng-to-string-before-insert-to-database – Mark Rotteveel Nov 06 '16 at 10:17

1 Answers1

0

You cannot directly insert a list in to Database . You are probably looking for

    String sql = "INSERT INTO table1 VALUES(";
        for(String s : list1)
        {
          sql = sql+"'"+s+"'"; 
          }    
           sql=sql+")";
                stmt.executeUpdate(sql);
sathya
  • 322
  • 2
  • 16
  • looking good, but android studio underlines 'String s' and say : " required latlng, found string" its possible to convert this here ? – patrick1980 Nov 04 '16 at 18:38
  • @patrick1980 so seems like you created your own variable named latIng, does it have certain values you want inserted in the object or what are you expecting to be inserted from each object – Orin Nov 04 '16 at 18:43
  • exacly adnroid studio say "required: com.google.android.gms.maps.model.LatLng , found java.lang.String" , i don't have my own variable named latlng – patrick1980 Nov 04 '16 at 19:01