2012-07-08 94 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 
}