File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "simple insert drives me nuts" Watch "simple insert drives me nuts" New topic

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

Joined: Oct 14, 2005
Posts: 19973

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.

steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
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). - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: simple insert drives me nuts
It's not a secret anymore!