I have converted a xml file using JAXB into java object. This Java object i have stored in arrylist and I want to store in db. Can you pls help
My action class
public class TimeRecord {
private static final String SUCCESS = null;
TimeDAOImpl timeDAOImpl=new TimeDAOImpl();
@SuppressWarnings("rawtypes")
public String activity(){
try {
// Directory path here
String path = "/home/anbarasi/Desktop/time";
String files = null;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
}
File file =new File(path+"/"+files);
JAXBContext jaxbContext = JAXBContext.newInstance(Activities.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Activities activities = (Activities) jaxbUnmarshaller.unmarshal(file);
for (int j = 0; j < activities.getActivities().toArray().length; j++) {
ArrayList list= activities.getActivities();
for (int k=0;k<list.size();k++){
list.get(k);
timeDAOImpl.addItem(list);
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@Sucess----"+list.get(k));
}
}
}
} catch (JAXBException e) {
e.printStackTrace();
}
return SUCCESS;
}
my DAO class
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.ts.Activity;
import com.ts.ConnectionFactory;
public class TimeDAOImpl {
private static Logger log = Logger.getAnonymousLogger();
ResultSet rs=null;
ResultSet rs1=null;
ConnectionFactory connectionFactory=new ConnectionFactory();
PreparedStatement pstmt=null;
PreparedStatement pstmt1=null;
@SuppressWarnings({ "rawtypes", "unchecked" })
List list =new ArrayList();
@SuppressWarnings("rawtypes")
public void addItem(ArrayList list){
try{
Connection con = connectionFactory.getConnection();
for (int i=0;i<list.size();i++){
System.out.println("@@@@@@@@@@@@@@@@@@@@@list3333= !!!!!!!!!!!!!success"+list.get(i));
String ls = (String) list.get(i);
System.out.println("@@@@@@@@@@@@@@@@@@@@@list3333 after success"+ls);
String query="insert into timeSheet values(?,?,?,?,?,?,?)";
pstmt=con.prepareStatement(query);
pstmt.setString(1, list.get(0).toString());
pstmt.setString(2, list.get(1).toString());
pstmt.setString(3, list.get(2).toString());
pstmt.setString(4, list.get(3).toString());
pstmt.setString(5, list.get(4).toString());
pstmt.setString(6, list.get(5).toString());
pstmt.setString(7, list.get(6).toString());
pstmt.addBatch(query);
//pstmt.executeUpdate();
}
}
catch (Exception e) {
log.config("Exception in TimeDAOImpl-->" + e);
}
return;
}
}