Saving ResultSet Data From JTable

Hi! I need help! I am using a JTable to display resultsets from an oracle database. I am retrieving the columns and rows from the DB and putting them into vectors. Then I return the table and display it in a JScrollpane. I have a button which searches the db table for my query and fills the JTable with the results. Now, I am trying to save that result using a JFileChooser or some form of saving method. Does anyone have any idea how I could do this? Thanks.

The JFileChooser will only give you a dialog that asks the user for a filename, it doesn't do the saving for you.
Your question belongs into the swing or general programming category, since the database portion is all working, but here's a hint:
You are trying to pull the data out of the table and save it to the file. Create a FileOutputStream for the filename the user choses in the file-choser, then iterate the rows and columns of the table (or the table's model (look at the JTable.getModel() method) and write the values to the file, maybe separated by commas and each row terminated by a carriage-return/linefeed combination.
This should give you a nice CSV file (that can be read by Excel) containing the data that is in your table.

Similar Messages

  • How to insert data from JTable to mysql Table....

    hello everybody
    i need help about how to insert data from JTable to mysql table... i know about how to create Table model...facing problem about how to insert data from JTable to mysql table....any helping link or code ... ill be thankfulll....for giving me solution...

    table1.getValueAt(table1.getSelectedRow(),0)you are getting the value of a selected row... or if you want you can just use a loop..
    for(.....){
    table1.getValueAt(x,y);
    }I think you know INSERT STATEMENT.. here on it just string concat
    sample e.g. (This not insert)
    "delete from accrule " +
                    "where ruleid= " + tblRA.getValueAt(tblRA.getSelectedRow(),0)+
                    " and accountname='"+tblRA.getValueAt(tblRA.getSelectedRow(),1)+"'"

  • Saving array data from a waveform chart

    I am using a CRIO 9004 and a 9237 bridge module to measure some strains from strain gauges. I've got one timed loop that reads the DMA FIFO and puts the arrays of values (16 data points, 4 per channel) into a queue. In the consumer timed  loop a For loop scales the binary data, auto indexes it into arrays, then the arrays are merged into a 2D array for the four channels  displayed on a waveform chart . Everytime the consumer loop runs it indexes 4 data points (per channel) yet the waveform chart plots them in a consecutive manner and doesn't overwrite the previous four. If I convert the arrays to waveform arrays I don't see anything on the waveform chart.
    If I pass the 2D array of data to a array indicator inside or outside the consumer loop I get only 16 data points. I want to save the information that appears on the waveform chart  after the consumer loop but because I'm not using waveform data type I can't use the write waveforms to file vi. The waveform chart history buffer has been set to 195360.
    Idealy we will run the four channels for 120 seconds charting the data and saving the data. The minimum data rate is 1613kS/s (403 per channel) The data can be saved after the loops have finished gathering and processing or while they are running. I noticed when I tried to write to TDMS it slowed the consumer down. Same thing if I use a shift register with the volume of data.
    I suspect I'm not sending data to the chart in the correct manner ( usualy takes two attempts to "clear chart" using shortcut menu).  I'm not too familiar with timed loops /producer consumer loops  and just tried to put something together based on examples.
    I've attached my host vi and front panel screenshot.

    Hope they appear attached this time.
    Attachments:
    Basic DMA (Host).vi ‏444 KB
    screenshot2.jpg ‏113 KB

  • Saving the data from an interactive adobe form

    Hi Gurus,
    I want to know how to upload the data from an interactive form (i.e the data sent by a person via email or URL.It is in XML format)  into the SAP database.
    Thanks,
    Raj

    Hi Vaibhav,
          I have designed an the interactive form which works both online and offline.In offline scenario when i am uploading the form the data form fields which has cardinality 1:1 are being fetched but how wil i fetch the data for the node of cardinality 0:n. i have used the code :
    node = document->find_from_name( name = 'attr' ).
    attr = node->get_value( ).
    attr is the attribute name of some node named node_info.
    When i use this code it fetched only the first line of the table i.e only the first value.
    How will i fetch the values for rest of the rows.Can u please guide me on this
    will reward points for sure.
    Thanks and Regards,
    srividya.

  • Saving the data from two info path forms in to a single list in share point 2010

    Hi ,
    I have two  info path forms are in share point page FM 1 and FM 2.
    In FM 1 I am getting data from lists by using drop down and casket drop down  and FM 2 i need to enter manually after entering
    i want to save both forms information(FM 1 & FM 2 ) in to a single list of  share point 2010
     If any knows the solution please reply me  
    Thanking You,
    Arun Darly

    Hi,
    Based on your description, my understanding is that you want to save the data from two info path forms in to a single list in share point 2010.
    We can't save the data from two info path forms in to a single list, but we can
    save the data from two info path forms in to a single library.
    Open the  FM 1 and FM 2 in Infopath(you have save it Locally once).
    Publish the FM 1 and FM 2 as content types named FM 1 and FM 2.
    Add the content types FM 1 and FM 2 into a document library, Then you can save the data
    from two info path forms in to a single library.
    Best Regards,
    Lisa Chen
    Lisa Chen
    TechNet Community Support

  • How to save data from JTable multiple rows and columns

    Hi Y_Not thanks for your help before...
    But what should I do if I want to get/save many data from many column and rows??

    i don't quite understand your (repeated) question. what is the problem with "multiple rows and columns". Y_NOT and i have shown you ways to access them.
    all you need are 2 loops: one around your number of rows and one around the number of columns or vice versa depending in which order you want to save things:
    for (int col = 0; col < data.size(); col++) {
        for (int row = 0 ; row < data[col].size(); row++) {
            // save your data
            saveData(data[col].getElementAt(row));
            // or use yourtable.getValueAt(row, col);
    }this is not a problem of Swing/Java but of simple algorithm...
    thomas

  • Importing / saving data from JTable

    Hi, are there any documents about this topic? Tutorials or anything?
    I do not want you to write it just a how to. cause if you write it im sure i wont be able to figure out how to put it in my code;)
    haha.
    thanks in forward

    Well, if you are using complex Object in your TableModel then the easiest way is probably to Serialize the TableModel. Problems with serializing is that the output file is rather large and the serialized file can only be read in by the same version of Java. (ie. its not portable between JDK1.4 and JDK1.5). This posting gives a simple example of using serialization:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=700384
    If you are just saving text Strings then you could create your own simple file structure to store the data and then parse it when you load the file. Use a structure like this:
    heading1|heading2|heading3|
    column1|column2|column3
    If you really want to solve the problem yourself then this posting was my attempt at explaining this process in a little more detail:
    http://forum.java.sun.com/thread.jspa?threadID=700031
    And if you want to see the final result of suggested solution from above check out:
    http://forum.java.sun.com/thread.jspa?threadID=700456

  • How can i gather data from jtable!

    hi!
    in fact i am trying to gather all the rowdata from my table sothat i can insert thel into my databse !
    could you plkease tell me how to deal with this?
    thanks

    As a simple case, let's assume that your JTable's column header names are in the same order as the columns in the database table to which you want to insert the JTable data. Also, let's assume all your table values are Strings.
    You'll need to do something like this (sorry if there are syntax errors - I'm not coding in an IDE...!):
      String tempStr = "insert into table_name values (";
      StringBuffer sb = null;
      Statement stat = dbConnection.createStatement();
      for (int i=0; i<tableModel.getRowCount(); i++) {
        sb = new StringBuffer(tempStr);
        for (int j=0; j<tableModel.getColumnCount()-1; j++) {
          sb.concat("'").concat(tableModel.getValueAt(i, j)).concat("', ");
        // for the last column
        sb.concat("'").concat(tableModel.getValueAt(i, tableModel.getColumnCount()-1)).concat(");");
        // your sb object now has the entire insert statement to put in the database
        stat.executeQuery(sb.toString()) ;
      }If the JTable columns are not in the same order, then you'll need to modify the above code to build your sql statement with the explicit column order you need.
    I hope this helps.
    Cheers!

  • Saving the data from the spool

    I have this big data dump(120,000 records) from the table mseg in the spool. I have to save that to a local file for some analysis purpose. Saving that as a local file is not giving me the full data.
    Please give me any suggestions to get the full data.
    Thanks in advance.
    Regards,
    Tony

    Looks like SAP has a limit to 10 Pages. But, this can be modified. SP01>Execute with your selection, then Menu>Goto--> Display requests > Settings> you see the option to increase the page count.
    The above change depends on memories. Hope this helps.
    -Mann

  • Possible to prevent Acrobat 7 saving private data from a form to temp file?

    I have a PDF order form with interactive fields that I want to post on my client's website. The form, created in Acrobat 7, is meant to be completed online then printed for faxing or mailing. It includes a field for a VISA number. I notice that once the form is filled in, the information persists even after closing and re-opening the PDF and the browser (in Windows XP, which I use, at least). If a user fills this form out at home, no problem. However, if a user fills it out at a public place such as an internet cafe, this is disastrous because anyone who opens the PDF thereafter will see the previous user's private information.
    Since I have no control over where users will be opening and completing this order form, is there any way I can set the PDF form to "purge" the field data when the file is closed, instead of saving it?
    Private data and especially credit card fraud is such a sensitive issue that any help would be much appreciated.

    You can clear the fields on the document will close event.

  • Capturing data from JTable and passing it to a class

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.table.AbstractTableModel;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import javax.swing.SwingUtilities;
    public class ProjectTable2 extends JFrame implements ActionListener
    JButton Up;
    // String lecturer_data[][];
    public ProjectTable2()
    super("Lecturer Table");
    setSize(300, 200);
    // addWindowListener(new BasicWindowMonitor());
    //JButton Up = new JButton("Update");
    //Up.addActionListener(this);
    //getContentPane().add(Up, BorderLayout.SOUTH);
    TableModel tm = new AbstractTableModel()
    //JTable jt = new JTable(tm);
    //JScrollPane jsp = new JScrollPane(jt);
    //getContentPane().add(jsp, BorderLayout.CENTER);
    Object[][] data = {
    {"Sandip", "Vekaria", "ee99c9", "A"},
    {"Manesh", "Mistry", "ee99b4", "A"},
    {"Barry", "Kwok", "ee99b6", "A"},
    {"Nikhil", "Nag", "ee99b3", "A"},
    {"Kevin", "Jervis", "ee99b1", "A"}};
    /* lecturer_data[][] = new String[data.length][4];
    for(int row = 0; row < data.length; row++)
    for(int col = 0; col <= 3; col++)
    lecturer_data[row][col] = data[row][col];
    String[] headers = {"First Name", "Second Name", "UserName", "Grades"};
    public int getRowCount() { return data.length;  }
    public int getColumnCount() {return headers.length; }
    public String getColumnName(int c) {return headers[c]; }
    public Object getValueAt(int r, int c) {return data[r][c]; }
    public boolean isCellEditable(int r, int c)
    if (c < 3)
    return false;
    else
    return true;
    /* Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int r, int c)
    try
    ProjectTable2 p = (ProjectTable2)data.elementAt(r;
    switch (c)
    case 0:
    return (String)p.val1;
    case 1:
    return (String)p.val2;
    case 2:
    return new Integer(p.val3);
    catch (Exception e)
    return "";
    public void setValueAt(Object value, int r, int c)
    if (c >=3)
    System.out.println("Setting value at " + r +", " + c + " to " + value);
    else {data[r][c] = value;}
    data[r][c] = value;
    fireTableCellUpdated(r, c);
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);
    Up = new JButton("Update");
    Up.addActionListener(this);
    getContentPane().add(Up, BorderLayout.SOUTH);
    public void actionPerformed(ActionEvent bc)
    // fireTableCellUpdated(r, c);
    if(bc.getSource()==Up)
    Lecturer nameGrades = new Lecturer("Raul Mondragon", "ele_956", true);
    // nameGrades.setTableDataUpdate(lecturer_data);
    //no_of_rows = tm.
    System.out.println("Update");
    // nameGrades.printDetails3();
    // nameGrades.printDetails4();
    //JTable jt = new JTable(tm);
    //JScrollPane jsp = new JScrollPane(jt);
    // getContentPane().add(jsp, BorderLayout.CENTER);
    public static void main(String args[])
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    ProjectTable2 pt = new ProjectTable2();
    pt.setVisible(true);
    Somebody please help!!

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.table.AbstractTableModel;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import javax.swing.SwingUtilities;
    public class ProjectTable2 extends JFrame implements ActionListener
    JButton Up;
    // String lecturer_data[][];
    public ProjectTable2()
    super("Lecturer Table");
    setSize(300, 200);
    // addWindowListener(new BasicWindowMonitor());
    //JButton Up = new JButton("Update");
    //Up.addActionListener(this);
    //getContentPane().add(Up, BorderLayout.SOUTH);
    TableModel tm = new AbstractTableModel()
    //JTable jt = new JTable(tm);
    //JScrollPane jsp = new JScrollPane(jt);
    //getContentPane().add(jsp, BorderLayout.CENTER);
    Object[][] data = {
    {"Sandip", "Vekaria", "ee99c9", "A"},
    {"Manesh", "Mistry", "ee99b4", "A"},
    {"Barry", "Kwok", "ee99b6", "A"},
    {"Nikhil", "Nag", "ee99b3", "A"},
    {"Kevin", "Jervis", "ee99b1", "A"}};
    /* lecturer_data[][] = new String[data.length][4];
    for(int row = 0; row < data.length; row++)
    for(int col = 0; col <= 3; col++)
    lecturer_data[row][col] = data[row][col];
    String[] headers = {"First Name", "Second Name", "UserName", "Grades"};
    public int getRowCount() { return data.length;  }
    public int getColumnCount() {return headers.length; }
    public String getColumnName(int c) {return headers[c]; }
    public Object getValueAt(int r, int c) {return data[r][c]; }
    public boolean isCellEditable(int r, int c)
    if (c < 3)
    return false;
    else
    return true;
    /* Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int r, int c)
    try
    ProjectTable2 p = (ProjectTable2)data.elementAt(r;
    switch (c)
    case 0:
    return (String)p.val1;
    case 1:
    return (String)p.val2;
    case 2:
    return new Integer(p.val3);
    catch (Exception e)
    return "";
    public void setValueAt(Object value, int r, int c)
    if (c >=3)
    System.out.println("Setting value at " + r +", " + c + " to " + value);
    else {data[r][c] = value;}
    data[r][c] = value;
    fireTableCellUpdated(r, c);
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);
    Up = new JButton("Update");
    Up.addActionListener(this);
    getContentPane().add(Up, BorderLayout.SOUTH);
    public void actionPerformed(ActionEvent bc)
    // fireTableCellUpdated(r, c);
    if(bc.getSource()==Up)
    Lecturer nameGrades = new Lecturer("Raul Mondragon", "ele_956", true);
    // nameGrades.setTableDataUpdate(lecturer_data);
    //no_of_rows = tm.
    System.out.println("Update");
    // nameGrades.printDetails3();
    // nameGrades.printDetails4();
    //JTable jt = new JTable(tm);
    //JScrollPane jsp = new JScrollPane(jt);
    // getContentPane().add(jsp, BorderLayout.CENTER);
    public static void main(String args[])
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    ProjectTable2 pt = new ProjectTable2();
    pt.setVisible(true);
    Somebody please help!!

  • Saving Form Data From GUI

    I have a GUI which aims to save client's details (Name, Address and Phone No) for an estate agency. There are two types of client: Buyers and Sellers and am trying to get the clients details saved into the appropriate class depending on which client type was selected on the JFrame. I have two packages:
    *uwePropertiesDomain
    *uwePropertiesUInterface
    uwePropertiesDomain contains the following classes:
    *Buyer
    *Seller
    uwePropertiesUInterface contains the following class:
    *uwePropertiesUI
    I have written the following code for the submit button on the JFrame:
    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt)
        if (evt.getSource() == submitButton)
            if (((String)clientTypeBox.getSelectedItem()).equals("Buyer"))
                uwePropertiesDomain.Buyer buyer = new uwePropertiesDomain.Buyer();
                //String[] clientInfo;
                buyer.save(new String[]{nameField.getText() , addressField.getText(), phoneField.getText()});
            else
                uwePropertiesDomain.Seller seller = new uwePropertiesDomain.Seller();
                //String[] clientInfo;
                seller.save(new String[]{nameField.getText() , addressField.getText(), phoneField.getText()});
        } And the following in Buyer/Seller classes:
    String[] clientInfo;    
    public void save(String[] args)
       this.clientInfo = args;
    }This all compiles, however, where is the data saved to? How would I go about searching for a client using their name?

    In your class, define a List such as ArrayList (easier than an array--you don't need to know the number of objects ahead of time).
    List buyerList = new ArrayList();
    List sellerList = new ArrayList();Then, in submitButtonActionPerformed, say:
    uwePropertiesDomain.Buyer buyer = new uwePropertiesDomain.Buyer();
    buyer.save(new String[]{nameField.getText() , addressField.getText(), phoneField.getText()});
    buyerList.add(buyer); // ADD THISAnd similar for seller.
    You may want a Buyer constructor that takes those three values, instead of having to call "save" separately.
    Now, you'll have a list of buyers and sellers, and you can perform searches on them (look up Comparable, redefining .equals/.hashCode, Comparator, etc.).

  • Post data from Jtable to word file

    I am a user of Jdeveloper
    and working on jclient\swing.
    The problem is that i want to post\Transfer data to a formatted word file. In word file there is a same table contaning same contents as jtable. Now after selection of a particular row \column the data of that row\column transfered to wor file table.
    i have no idea about it.
    Help me for the Same
    thnkx.

    hi,
    have a look at POI , an apache open source project. POI handles Excel and Word files. But i don't know whether it will solve your problem.
    Gernot

  • Saving the data from a dead library

    So I've given up trying to rebuild my library (see here: http://discussions.apple.com/thread.jspa?messageID=11544400&#11544400) and was wondering if anyone had any thoughts on how I could extract the projects from an Aperture 3 library.
    In an Aperture 2 library you could view the package contents and each project was bundled into a package along with all setting, versions, etc. This is not the case with A3. If you view the package contents of and A3 library everything is spread out. Masters, Projects, Folders and Version are separate from one another.
    Any thoughts?
    I've many of my projects backed up but recent work that consisted of a lot of image processing is now lost in the dead library.

    I think I have recovered my library. I'm in the process of checking the projects to see if they are all intact.
    Here is what I did:
    1: Created a new empty library
    2: Quit Aperture
    3: Viewed the contents of the package of the new library and viewed the contents of the old damaged library
    4: Moved the "Masters" folder from the old to the new library
    5: Moved the "Aperture.aplib" folder from the old to the new library
    6: Moved the "ApertureData.xml" file from the old to the new library
    7: I then opened the "Database" folder in the old library and copied the following folders: "Albums", "Folders" and "Versions"
    Everything else I left behind.
    I then launched Aperture by doubleclicking on the new library while holding the Command and Alt keys and selected "Rebuild Library" from the Library First Aid panel.
    Aperture then began processing all the content. 10900 images later Aperture launched showing all projects and images.
    Looks good so far...

  • Saving all data from a while loop

    I already asked a similar question but it might not be very clear and there were some concepts that I could not well understand.
    1. I have a key pad to generate DTMF stream signal (I call it stream because it contains multiple tones which make up of a complete phone number)
    2. I would like to save it as a wav file but I guess other format is okay and because the write to wav file does not support append so for this particular case, I use write to waveform instead of write to wav
    My approach is to have a queue structure so I can write each iteration result to a file.
    i)When I try to retrieve the data, there is nothing but 0.
    ii)my intention is to get 8000 sample per second (fs = 8,000) but it save the data so fast
    I attached the file so if there is way to solve the problems, please help me. 
    Solved!
    Go to Solution.
    Attachments:
    SignalGenerator.vi ‏52 KB

    I believe what is happening is that your producer loop is iterating even when there is no key press and sending blank or default data to the consumer and overwriting the test.wav file.  
    Easy way around this is to put an event structure in the producer that only enqueues data when there is a key press.   I can't see into the Mathscript node so I'm not sure what's going on there, but I suspect the default output (e.g all of the Booleans are false) is for zero-length arrays on f1 and f2 and this is getting enqueued and overwrites any real data that might have been in test.wav.
    It should be possible to append to a .wav.  I have attached a proposed method.  Caution that this in your consumer will take longer and longer as the file grows as it needs to read in the file every time.  
    Attachments:
    Untitled 3.vi ‏8 KB

Maybe you are looking for