• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple insert drives me nuts

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

The end-user sees a JTable gui with some data/elements in it (title, name�). He can have them ordered in any way he wants, when he clicks save and later comes back to the table he should see the order he previously saved.

For some reason, when he clicks save the first time � the data is saved in the same ordered he requested, however the second time he clicks save, the order is reversed.

I realized the elements are saved reversed in the database.

any idea why?

The code looks like this:




and then insert:

 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't shown the SQL that is relevant to your question, namely the SELECT statement that you are complaining about. If you want your data ordered in a certain sequence then you have to arrange that by providing an ORDER BY clause when you select the data. So what does your ORDER BY clause look like?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no "ORDER BY" as the end user determines the order.

The select is straight forward:
SELECT * FROM guestTable WHERE groupId=?
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, relational DB managers are free to return results in any order, even a random one.

In the absence of an ORDER BY clause.

Guy
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a few of the posters have said. If order is important you need to be explicit in SQL. Order should be thought of as undefined by default. For example in Sybase ASE your order can be changed when the dba decides to implement a clustered index on your table (or remove it).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic