Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Regarding JAXB

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regarding JAXB

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

    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Regarding JAXB

    This section is for saying hi, not for asking questions. See the sticky at the top of this section, and read the forum rules.
    Also use [code=java] before your code and [/code] after your code.
    Asking a specific question will get you more help than saying what you want your code to do and dumping code.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Regarding JAXB

    Thread moved from Members Introductions
    Please read http://www.javaprogrammingforums.com...uncements.html

Similar Threads

  1. How to parse an object to and from XML using JAXB
    By Json in forum File Input/Output Tutorials
    Replies: 1
    Last Post: August 8th, 2013, 05:45 PM
  2. Jaxb-- java file generation for DTD
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: November 22nd, 2011, 02:21 AM
  3. Which tech to use JAXB or XSTREAM ?
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: November 7th, 2011, 01:33 AM
  4. JAXB 2.0: Some elements are ignored during Marshalling. Why? How do I fix this?
    By Charlie Irongleet in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: October 21st, 2011, 03:58 PM
  5. How to parse an object to and from XML using JAXB
    By Json in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 20th, 2010, 03:42 AM