Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2006

Tip: Looking for answers? Try searching our database.

JTable - problem with reading values from cells(values that was changed )

Thread view: 
wierus - 21 Mar 2006 12:46 GMT
Hi! I write an application and I use JTable object to present data from
database. I try to read data from cells and if it was changed ,change
it in the database. I have a problem with it. My function reads cells
in a wrong way, e.g it always shows wrong last changed value (it shows
it if it wasn't change - the original value as in database).
It is no matter if user changes values in 3 or 8 cells in the row,
function always shows wrong last value (e.g. 3-th or 8 th value )
Example
Original table(from resultset)
a|b|c|d|e|f
Modified table
a|e|h|k|l|f
-------
my function reads values from modified table like this
"a|e|h|k|e|f"
so, some values are read correct and one(always the last changed one)
is read wrong (as it would be read from original resultset not from the
modified table!!!!)

I don't know why...If you have any idea please let me know

This is my code

try
    {
   q_tym="UPDATE administrator.oddzial SET
oddzial.nazwa_o=?,oddzial.ulica=?,oddzial.numer=?,oddzial.miasto=?,oddzial.kod_pocztowy=?,oddzial.kraj=?

WHERE oddzial.nazwa_o=? ";
         stmt_tym=conn.prepareStatement(q_tym);
         rset.beforeFirst();
         for(int i=0;i<liczba_wier;i++)
          {
           liczba_zmian_linii=0;
           rset.next();
           for(int j=0;j<liczba_kol;j++){

            if(!this.tym.getValueAt(i,j).equals(rset.getString(j+1)))
               //i checke here if original values are different from
these in jtable to determine which cells were changed by user
               {

JOptionPane.showMessageDialog(null,this.tym.getValueAt(i,j).toString());

JOptionPane.showMessageDialog(null,rset.getString(j+1));
                      //here i check values to determine where is the
problem with reading wrong values

                      liczba_zmian_linii++;
               };
           if(this.tym.getValueAt(i,j).equals(rset.getString(j+1)))
              //i check here which read values are recognized as
equals to see if my function works properly

                    {

JOptionPane.showMessageDialog(null,this.tym.getValueAt(i,j).toString());

JOptionPane.showMessageDialog(null,rset.getString(j+1));
                     }

            }

             if(liczba_zmian_linii>0)

              {
               wynik_zapisu++;

stmt_tym.setString(1,this.tym.getValueAt(i,0).toString());

stmt_tym.setString(2,this.tym.getValueAt(i,1).toString());

stmt_tym.setString(3,this.tym.getValueAt(i,2).toString());

stmt_tym.setString(4,this.tym.getValueAt(i,3).toString());

stmt_tym.setString(5,this.tym.getValueAt(i,4).toString());

stmt_tym.setString(6,this.tym.getValueAt(i,5).toString());
               stmt_tym.setString(7,rset.getString(1));
               stmt_tym.executeUpdate();

//JOptionPane.showMessageDialog(null,this.tym.getValueAt(i,0).toString());

//JOptionPane.showMessageDialog(null,this.tym.getValueAt(i,1).toString());
                //

JOptionPane.showMessageDialog(null,this.tym.getValueAt(i,2).toString());
               }
David Harper - 23 Mar 2006 08:04 GMT
Dear Wierus,

> Example
> Original table(from resultset)
[quoted text clipped - 7 lines]
> is read wrong (as it would be read from original resultset not from the
> modified table!!!!)

Your code fragment is not easy to understand, partly because your
variable names are in Polish but mainly because you do not make it clear
how this code fragment is being used.

If you are listening for changes to the contents of the JTable caused by
the user editing cells, then I assume that you have added a
TableModelListener to your table model, and that you are sending updates
to the database in response to TableModelEvent.UPDATE events.

But that is not obvious from your code fragment.

You say that the last changed value in the row is always incorrect. Is
it possible that you are looping over too few items in the row, and not
actually updating the last changed value at all?

Good luck with your problem.

David Harper
Cambridge, England


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.