2012-07-08 96 views
0

我加入类对象为我的数组列表,现在我要重复在一个循环中的对象并保存到数据库迭代类对象的ArrayList中的Java

我bean类

public class SchemeBean { 

private String code; 
private String name; 
private String value; 

public String getCode(){ 

return code; 

} 

public String getName(){ 

return name; 

} 


public String getValue(){ 

return value; 

} 


    public SchemeBean(String code,String name,String value){ 

this.code=code; 
this.name=name; 
this.value=value; 


} 

}

在阵列中添加的类对象

ArrayList items= null ; 
    String hd1 = jsonLineItem.getString("hd1"); 
    String hd2 = jsonLineItem.getString("hd2"); 
    String code = jsonLineItem.getString("code"); 
    items.add(new SchemeBean(code,hd1,hd2)); 

现在我有具有克此ArrayList项SchemeBean的对象添加到它的元素

现在我的要求是,我必须迭代它并将其添加到数据库IAM不理解如何迭代它。请任何暗示会为我

回答

0
for(SchemeBean item: items){ 
    System.out.println("item: "+item); 
} 

一个greeat帮助虽然你将需要重写为正确的输出toString方法。

0
for(int i=0; i<items.lenth-1; i++) 
{ 
    Save(item[i]); 
} 

或者......

for (SchemeBean s : arrayList) 
{ 
    Save(item[i]); 
} 

您保存功能骨架...

public void Save(SchemeBean s) 
{ 
    //Save the values to the db 
}