File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes simple insert drives me nuts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "simple insert drives me nuts" Watch "simple insert drives me nuts" New topic
Author

simple insert drives me nuts

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Sep 10, 2004
Posts: 755
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

Joined: Nov 24, 2000
Posts: 776
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

Joined: Jun 26, 2002
Posts: 861
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).


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: simple insert drives me nuts