【问题标题】:The list is not transferred into the database该列表未传输到数据库中
【发布时间】:2016-11-04 17:55:58
【问题描述】:

我的数据库中有一个表table1。此表有一列 column1 设置为 varchar(20)

我的所有数据都在ArrayList<LatLng> list1

现在我尝试将我的list1 插入到column1,但我的想法没有奏效:

 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();
            }
        }

这里有什么问题?

【问题讨论】:

标签: java mysql jdbc arraylist


【解决方案1】:

您不能直接将列表插入到数据库中。您可能正在寻找

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

【讨论】:

  • 看起来不错,但 android studio 在“String s”下划线并说:“需要 latlng,找到字符串”可以在这里转换吗?
  • @patrick1980 所以好像您创建了自己的变量 latIng,它是否具有您想要插入到对象中的某些值,或者您希望从每个对象中插入什么
  • exacly adnroid studio 说“需要:com.google.android.gms.maps.model.LatLng,找到 java.lang.String”,我没有自己的名为 latlng 的变量
猜你喜欢
  • 2015-07-24
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
  • 1970-01-01
  • 1970-01-01
  • 2021-11-07
  • 1970-01-01
相关资源
最近更新 更多