Results 1 to 7 of 7
  1. #1
    sweet angle is offline Member
    Join Date
    Jul 2008
    Posts
    22
    Rep Power
    0

    Question editing jTable then writing new values to database!

    hi every one ..
    i'm wondering how can i detect that jtable is currently editing and then store the new values to my data base?
    i have used the following code:

    if(jTable1.isEditing())
    {
    int index=jTable1.getEditingRow();
    if(index!=-1)
    {
    jTable1.getValueAt(index,0);
    sql = "INSERT INTO announcement (ann_txt,cNo) VALUES ('" + jTable1.getValueAt(index,0).toString()+ "','"+ GlobalData.courseNo+ "');";
    res = st.executeUpdate(sql);
    }
    }
    was that the right code...if it's.. where should i put this code?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    > was that the right code...
    Why, did you get it from an unreliable source?

    > where should i put this code?
    In your program?

    db

  3. #3
    sweet angle is offline Member
    Join Date
    Jul 2008
    Posts
    22
    Rep Power
    0

    Default

    i'm sorry ...maybe my question was'nt clear..
    what i ment is how can i use fireTableChanged when i'm using DefaultTableModel

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    DefaultTableModel should fire TableModelChanged events for you. You need to add a listener to the TableModel and figure out what the different events mean. When you see the appropriate event, you can then invoke your database update code.

  5. #5
    sweet angle is offline Member
    Join Date
    Jul 2008
    Posts
    22
    Rep Power
    0

    Default

    thanks alot "Steve11235"..
    but i have another annoying question..
    can you give me any links that explain how to -->add a listener to the TableModel
    thanks in advance..

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Sun's Java Tutorials cover just about everything.

  7. #7
    sweet angle is offline Member
    Join Date
    Jul 2008
    Posts
    22
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 12-12-2008, 03:35 PM
  2. Getting integer values from a JTable
    By zikojam in forum New To Java
    Replies: 1
    Last Post: 12-11-2008, 02:06 PM
  3. writing array values to another class
    By ronald christian in forum New To Java
    Replies: 27
    Last Post: 11-07-2008, 04:08 PM
  4. JTable editing with Mouse
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 0
    Last Post: 10-11-2008, 08:34 AM
  5. jTable Cell editing
    By mahaling_m in forum AWT / Swing
    Replies: 0
    Last Post: 06-23-2008, 08:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •