Updating resultsets using vectors in editable JTables

Ok i am currently retrieveing my result from a vector of vectors from a query:
public void presentResultSet (ResultSet rs)throws SQLException {
Vector dataVector=new Vector();
try
{if (!rs.next())
    JOptionPane.showMessageDialog(null, " No records for student" );
  else {
    do{
     Vector rowVector=new Vector();
     rowVector.addElement(rs.getString("studentID"));
     rowVector.addElement(rs.getString("moduleID"));
     rowVector.addElement(rs.getString("examMark"));
     dataVector.addElement (rowVector);
    }while(rs.next());
} tab.setData(dataVector);
dataTableScrollPane.setViewportView(dataTable);}
catch (Exception f){ System.out.println (f.getMessage());
This method is fine actually as it displays the results onto my GUI. But problem is, i want to add another feature of the system where users can click on any cells in the JTable, edit it and JTable will be able to help me update it onto my tables in mysql.
I have set the public boolean iseditable into true.
but can anyone tell me how to write the public void setValueAt method ? how to retrieve that information that the user type into the particular cell and update it onto the database ? Please help !

Ok I assume because your using a JTable that you are using your own TableModel because the DefaultTableModel usually won't do everything you want. So if your not extending DefaultTableModel you need to start there.
In your Table model you need a method called setValueAt which will overide the DefaultTableMode.setValueAt().
Your TableModel's setValueAt() will get called by the table Cell Renderer when ever a cell is edited.
So to break down setValueAt(Object aValue,int aRow,int aColumn)
Object aValue = is whatever the user has entered in the Cell. Now its an Object and not a String because you can have all sort of things in a JTable Cell such as checkboxes,buttons, etc.
The int Row and int Column are pretty self explanitory.
I don't know what your table looks like but lets say you have have 3 columns
StudentID,ModuleID,ExamMark you could do something like this
public void setValueAt(Object aValue,int aRow,int aColumn)
        // In your table model there should be some Vector that contains your other 
        // Vectors. In this example "rows" is that Vector
       // this assigns rowVector the Vector of Columns at the row
       // that was edited by the user in the JTable. It should contain the 3 columns
       Vector rowVector = (Vector)rows.elementAt(aRow);
        // this will overwrite the current value at that column
        rowVector.setElementAt(aValue,aColumn );
        // you may need to cast aValue into whatever Object you plan on storing probably a string
        // ie. rowVector.setElementAt((String)aValue,aColumn );
} Your Table Model should now contain the new value in its rows Vector all you have do is add someway to save that new Vector back into the Database.
Hope this helps I didn't compile it but I think it will work or at least give you a better understanding....
Or maybe I confused you more.
Good Luck
Justin

Similar Messages

  • How to create updateable resultset using sql with "order by"

    Dear all,
    I'm using the Derby database to hold a table of stock prices. After the table is populated, I want to do some calculations and store the result in a column.
    I get the resultset using the following code
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(select history_id, value, days from history where ticker = '" + ticker + "' order by value_date"); {code} When I then try to update the "days" field, I get an SQLException telling me that the resultset is not updatable. However, if I remove the "order by" clause, I am able to update the data, but then my algorithm does not work as I need to traverse the data in a specific order. The quesion is: how do I create an updatable resultset using a sql-statement with an order by clause? Kind regards Karl Martin Lund                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    jschell wrote:
    Seems rather obvious to me that the exception specifically tells you that you can't do that.OP: I would guess it's because ORDER BY forces the database to read all the result rows into a temporary area, sort them, and then return them from this temporary area, as opposed to streaming the results. The extra step probably makes updateable result sets more difficult (or maybe not possible), so they opted not to do it.

  • HT2506 I use Preview to edit photos, and would like to know if there are any Preview updates in the works. I find there is a problem with Preview crashing, or taking a very long time to "catch up" (spinning beachball of death) while I'm editing.

    I use Preview to edit photos, and would like to know if there are any updates to this program in the works. It seems Apple is constantly updating its software, except for Preview. I find it crashes all too often, and also takes forever to "catch up" with me (as in spinning beachball of death) when I'm editing a lrge amount of photos. Yes, I know I should be using Photoshop or somesuch, but it's just too **** confusing, and I don't have the time to figure it out. Thanks!!

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Step 1
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Enter the name of the crashed application or process in the Filter text field. Select the messages from the time of the last crash, if any. Copy them to the Clipboard (command-C). Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.
    Step 2
    In the Console window, look under User Diagnostic Reports for crash reports related to the crashed process. The report name starts with the name of the process, and ends with ".crash". Select the most recent report and post the entire contents — again, the text, not a screenshot. In the interest of privacy, I suggest that, before posting, you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header of the report, if it’s present (it may not be.) Please don’t post shutdownStall, spin, or hang logs — they're very long and not helpful.

  • How to use vector in JTable? Please help......

    Hi there
    I can use JTable using object array to manupulate data but it has a limitation of defining number of rows of the array. Alternatively i want to use vector. Anyone help me how to convert to using vector.
    Regards.
    mortoza, Dhaka

    hi,
    you could either use javax.swing.table.DefaultTableModel because this class uses a java.util.Vector for data storage or you could implements your own TableModel by extending javax.swing.table.AbstractTableModel.
    best regards, Michael

  • Problem in storing of the resultset in vector and updating comboboxes

    i'm using Vectors to store the data which i got from the resultsets. all that is working fine. i display this data in a vector in a JComboBox. but my method is resetting the vector itself eventhough i'm not touching it at all. the code is as follows
    int in=canteen_text.getSelectedIndex();
    System.out.println(item_description[in]);
    for(int i=0;i<10;i++)
         item_name.removeAllItems();
         for(int j=0;j<item_description[in].size();j++)
              item_name[i].addItem(item_description[in].elementAt(j));
         item_name[i].setSelectedIndex(0);
    here canteen_text is a JComboBox,
    item_description[] is my array of vectors
    item_name[] is my array of JComboBox
    i still can't understand how this code is resetting item_description[0].
    plz help!!!

    Don't cross-post:
    http://forum.java.sun.com/thread.jsp?thread=472970&forum=424&message=2188783
    http://forum.java.sun.com/thread.jsp?thread=472969&forum=57&message=2188781
    http://forum.java.sun.com/thread.jsp?thread=472968&forum=422&message=2188779
    http://forum.java.sun.com/thread.jsp?thread=472966&forum=31&message=2188776
    http://forum.java.sun.com/thread.jsp?thread=472932&forum=48&message=2188536
    MOD

  • On iOS 8.3 using 'Keynote for iPad' the app freezes repeatedly (since the last update of April 21st) while editing slides. 30 sec. later comes alive again, then freezes again after a few editing actions. Anyone with the same problem?

    On iOS 8.3 using 'Keynote for iPad' the app freezes repeatedly (since the last update of April 21st) while editing slides. 30 sec. later comes alive again, then freezes again after a few editing actions. Anyone with the same problem?  I tried everything 'app support' tells me except deleting and reinstalling the App because I have a lot of files that I'd lose.  Recommendations anyone?  [email protected]

    On iOS 8.3 using 'Keynote for iPad' the app freezes repeatedly (since the last update of April 21st) while editing slides. 30 sec. later comes alive again, then freezes again after a few editing actions. Anyone with the same problem?  I tried everything 'app support' tells me except deleting and reinstalling the App because I have a lot of files that I'd lose.  Recommendations anyone?  [email protected]

  • Using updatable ResultSet to update Unicode data ?

    Is it possible to use Unicode data in updateString() methods for updatable resultset ? Or I only can do it using OraclePreparedStatement ? I've opened an updatable ResultSet and trying to update NCHAR column using the code below:
    rset.updateString(6, "\uFF23\uFF23");
    which fails with "java.sql.SQLException: Cannot map Unicode to Oracle character".
    An attempt to do the same thing with regulair English data
    rset.updateString(6, "CC");
    causes "java.sql.SQLException: ORA-12704: character set mismatch" on insertRow(). The server primary encoding is UTF8 and I have AMERICAN_AMERICA.UTF8 in NLS_LANG in the registry. I would really appreciate any help on this ...

    Thanks ! I guess I was looking in the wrong jdbc directory (the one that comes with JDev) ...

  • Need to use vector to insert data into JTable?

    hi
    i'm trying to insert data from mssql 2000 into JTable. The number of columns are fixed, but the number of rows are not, since it will depend on how many data retrieved from the database.
    The documentation says that vector class implements a growable array of objects, and I've seen some examples using vector such as from http://forum.java.sun.com/thread.jspa?forumID=57&threadID=238597 .
    I would like to know, in my case, do i need to set my column and row to use vector? or should i only set rows to use vector ? (since the row size will vary, while the column size will stick to 6).

    Because your JTable operation will be done on a table model, the selection of the initial data
    structure for the model is almost non-issue. In other words, whatever will do.
    See the javadoc for the DefaultTableModel class, which you will eventually use, especially the
    construcotr part.

  • Cannot get itunes to update to 10.5 using xp media edition?

    cannot get itunes to update to 10.5 using xp media edition?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes for Windows forums.
    Regards.

  • HT1657 i am trying to watch a movie using my appve TV, but i am asked to verify 'payment' info on itunes store. i have updated everything using the 'edit' button, it still isn't working and i am frustrated, 6465107522

    i am trying to watch a movie using my appve TV, but i am asked to verify 'payment' info on itunes store. i have updated everything using the 'edit' button, it still isn't working and i am frustrated, 6465107522

    perhaps this will help?
    h t t p://w w w.aone-soft.com/mobile_3gp_video_converter.htm
    or do a google search on  "mobile_3gp_video_converter"
    Message Edited by JSanders on 11-18-2008 09:43 AM
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Using Vector to display ResultSet on multiple pages

    Hi all,
    I want to use Vector for Displaying the ResultSet in multiple pages for my JSP.
    Can anybody assist me on how to display Resultset on multiple pages by using Vectors.
    Thanks for any help in advance.
    regards,
    savdeep

    Haii Pls go through the code
    Vector v=new Vectior()
    while(rs.next())
       v.add(rs.getString(column name));
    v //vector is readyyyyyregards
    Shanu

  • Start or stop edit jtable cell editing

    Hello,
    I got a problem with the jtable DefaultModel isCellEditable.
    If I set the IsCellEditable to false, I would not be able to enable the cell selection as and when I want it.
    What I have in mind is the add a mouselister so that if the user select a row using fast left mouse click like the procedure shown below
    private class MouseClickHandler extends MouseAdapter {
    public void mouseClicked(MouseEvent event) {
    int no_mouseclick = 0;
    no_mouseclick = event.getClickCount();
    if (no_mouseclick >= 2) {
    int cur_row = 0;
    cur_row = table.getSelectedRow();
    // table.setColumnSelectionAllowed(true);
    // table.setRowSelectionAllowed(true);
    for (int i=0;i<table.getColumnCount();i++){
    table.editCellAt(cur_row,i);
    System.out.println("mouse row--->" + cur_row);
    I could overwrite the IsCellEditable to true to enable that particular or cell contains in that row to be able to accept input and overwrite any data which in my case obtained from the Sql database a sort of like input module using tabulation . I am also thinking of using text component or combobox to display the value for user selection , but I do not know how to enable a particular cell for editing if the Jtable created is using a non-editable DefaultModel. If I set the IsCellEditable to true, every single cell would be enable for editing , and this defeat the purpose of enable user input only upon double mouseclicks.
    By the way , I am interested to know how to track the data changes in the cell within the jtable so that only those have been modified are notify from the Table model and updated into the Sql table
    Could anyone of you out there provide some hints please
    Thanks

    Hello,
    Tablemodellistener could detect the changes in the data, how about the backend database updating and transactional activity that must be associated with the data changes?
    What is on my mind is that , the moment there is changes in the data detected by the TableModellistener, whatever records associated with or brougt up by Jtable would be all deleted from the database and then follow by the new set of new records to be inserted into the database. The disadvantage of this method is that everytime the backend database connection and activity need to be executed the moment there is a change in the data in the jtable cell. For example the user may be just amendment to only one cell , but all the records associated need to be deleted and then inserted again.
    Perhaps there are better solution to deal with Jtable and JDBC backend connection where in this case, I am using JDO to undertake the database activity like the observable modelling .
    Could someone provide the hint please
    Thank

  • How to add a new record in updatable report using apex_item

    Hi,
    i am using an updatable report using the following select
    select
    aPEX_ITEM.POPUP_FROM_QUERY(2,emp_code,
    ' SELECT emp_surname, emp_code FROM hrm_employee ' ,null,null,null,null,null,'onchange="f_set_multi_items_tabular(this.value ''#ROWNUM#'''
    || ')"',null,null,null) PF_No,
    apex_item.text (32,
    NULL,
    80,
    100,
    'style="width:190px" ',
    'f11_' || '#ROWNUM#'
    ) Name,
    " REST_DATE",
    "REMARKS",
    from "roster"
    when i click on the button add row , only the column rest_date and the remarks are enable.
    why is the apex_item.text and apex_item_popup_from_query is disable ? and how i can make it enable.
    thanks
    regards
    jerry

    I could see that you are using the addRow() function to generate new blank row.
    I guess, this function(used by the builtin tabular form s) , identifies editable columns when they are marked so at the report column attributes.
    When you use apex_item API, it expects the columns to be standard report column and hence render the new rows as such.
    Some one from the development team might be able to give a better answer on that.
    As for avoiding this issue
    <li>One method , would be to define the columns editable(and display types) in report column attributes.
    <li> You can duplicate the last row using jQuery( *$('tr.highlight-row:last).after( $('tr.highlight-row:last).clone() )* ) and removing the field values, but events(for example datepicker) would remain attached to the original row , so it isn't very straightforward either.
    <li>If you want to use apex_item you would have to use a pseudo union to DUAL for generating a blank row and re-render the report either by a page load or a Dynamic Action. Sounds like a nice idea for a plugin.
    Now , if you want to add rows multiple times without saving them, then you would need to store the values in a collection at load and update the collection before adding the row.

  • How to upload an image from my computer using in-browser editing

    When I use in-browser editing to change an image on my Muse site, there is not an option to upload the image "from my computer" like it shows in the documentation.  How can my clients update an image on their Muse sites from their own computers?

    Hello Cheny,
    Please check if the suggestions made here helps resolve the issue: http://forums.adobe.com/message/5687159
    Cheers
    Parikshit

  • Problem in storing of the resultset in vector

    i'm using Vectors to store the data which i got from the resultsets. all that is working fine. i display this data in a vector in a JComboBox. but my method is resetting the vector itself eventhough i'm not touching it at all. the code is as follows
    int in=canteen_text.getSelectedIndex();
    System.out.println(item_description[in]);
    for(int i=0;i<10;i++)
         item_name.removeAllItems();
         for(int j=0;j<item_description[in].size();j++)
              item_name[i].addItem(item_description[in].elementAt(j));
         item_name[i].setSelectedIndex(0);
    here canteen_text is a JComboBox,
    item_description[] is my array of vectors
    item_name[] is my array of JComboBox
    i still can't understand how this code is resetting item_description[0].
    plz help!!!

    Don't cross-post:
    http://forum.java.sun.com/thread.jsp?thread=472970&forum=424&message=2188783
    http://forum.java.sun.com/thread.jsp?thread=472969&forum=57&message=2188781
    http://forum.java.sun.com/thread.jsp?thread=472968&forum=422&message=2188779
    http://forum.java.sun.com/thread.jsp?thread=472966&forum=31&message=2188776
    http://forum.java.sun.com/thread.jsp?thread=472932&forum=48&message=2188536
    MOD

Maybe you are looking for

  • Delete photo in iCloud photo stream?

    Hi, is there a way to delete an individual photo in photo stream in your IOS 5 device?

  • Playing a movie on my tv

    Ok, so maybe I should post this in the HP forums, but I will try here first. I have an HP Media Laptop. I can connect my laptop to my tv with an HDMI cable. This allows whatever I am doing on the laptop screen to appear on my tv. What I want to do is

  • Samples Analysis Schedules

    Dear all i want to create daily,weekly,monthly,yearly analysis schedules.

  • Help me with this error: swf display wrong

    Recently i met below error when compiled my flex project: lost characters of font in my flex, see below picture to understand: 1. Original UI in flex builder 2. But after i compile it, and result on browser: anyone can help me,please...

  • How to resume Net installer?

    All-- The Net install program for WLS 7.0 SP2 looses its connection prior to completing the download of the "installation archives" and I can't get it to resume. How do I complete the download? This has now happened twice. 1. On the first time I trie