Results 1 to 14 of 14
  1. #1
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default Database not updated in an order of the insertion of the data..!

    I am actually trying to update the database (In Oracle) using jdbc...

    In particulars, i have a gui that accepts data valus from the user and then inserts these values into the databases.
    Now the problem is that the data is not inserted in the order of the updation of the database... i mean the entry made first should be before the entry made second.. but it is not actually happening..:(

    I need the database to be updated in the order of the insertion because.. i need to fetch the entries from the very few lasts

    please suggest ! thnx.
    The Quieter you become the more you are able to hear !

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Do you have an index on one (or more of the columns)? If so the data will most likely be fetched in that index order, otherwise no particular order is guaranteed and you have to install an index on that table (preferably on an "auto increment" column).

    kind regards,

    Jos

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Put simply, there is no order in a database table.
    It's a meaningless concept.

    There is only order in a query that has an ORDER BY in it.

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by Stephen Douglas View Post
    I need the database to be updated in the order of the insertion because.. i need to fetch the entries from the very few lasts

    what do you mean with "very few lasts"? if i understand your problem you could add a field of type timestamp in your table. this field could then be the operational criteria for "very few lasts".

  5. #5
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    thnx for your replies..

    a field of type timestamp in your table
    How can i create a field of type timestamp ????????
    i mean i am new to databases.... and the only available types that i see in the netbeans are
    NUMERIC , FLOAT, VARCHAR2, REAL, DATE, INTEGER, CHAR, SMALLINT, DECIMAL, INT, BLOB.
    please help.

    Put simply, there is no order in a database table.
    means.. when an entry is made to the databases then it can be updated to any of the rows?? have i understood correct ? means entry made at the 8th place in the order of entries , not necessarily will be added to the 8th place in the table.

    JosAH can you please provide me the link where i can learn more about indexing? thnx.
    The Quieter you become the more you are able to hear !

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Stephen Douglas View Post
    JosAH can you please provide me the link where i can learn more about indexing? thnx.
    That's a SQL thing and I bet your Oracle distribution comes with a manual that explains all about indexes. Some database engines automagically create an index on the primary key of your table.

    kind regards,

    Jos

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Quote Originally Posted by Stephen Douglas View Post
    thnx for your replies..



    How can i create a field of type timestamp ????????
    i mean i am new to databases.... and the only available types that i see in the netbeans are
    NUMERIC , FLOAT, VARCHAR2, REAL, DATE, INTEGER, CHAR, SMALLINT, DECIMAL, INT, BLOB.
    please help.
    DATE will do you if you only need precision to the second, but TIMESTAMP will be better if you want it to (I think) milliseconds. but an id field would be better.

    Quote Originally Posted by Stephen Douglas View Post
    means.. when an entry is made to the databases then it can be updated to any of the rows?? have i understood correct ? means entry made at the 8th place in the order of entries , not necessarily will be added to the 8th place in the table.
    No. What it means is, when you insert a row into a table then the database can put it wherever it likes. There is no order. There is no such thing as "8th place". So, if I have a table with 10 rows in it, and then add another row, then do a "SELECT * FROM my_table", that new row could appear anywhere in the returned results. And each time you run it it may (very rarely) give you the rows back in a different order.

    The only way to change this is to, as mentioned above, use something like an auto-generated id field (Oracle uses sequences), or (not as good) a timestamp, and then doing "SELECT * from my_table ORDER BY id" or "ORDER BY my_timestamp".

    Quote Originally Posted by Stephen Douglas View Post
    JosAH can you please provide me the link where i can learn more about indexing? thnx.
    As a db term an index is something else entirely. I think Jos is referring to what I refer to above with sequences....ie an id field that is a unique (and incrementing) number.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    DATE will do you if you only need precision to the second, but TIMESTAMP will be better if you want it to (I think) milliseconds. but an id field would be better.
    Many database engines are very well capable to insert more than one record in a table within a millisecond. IMHO an auto increment field would do fine.

    kind regards,

    Jos

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Which is why I was advocating an id field.
    There is no such thing as an auto-increment in Oracle, you use sequences and a regular number field.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    Which is why I was advocating an id field.
    There is no such thing as an auto-increment in Oracle, you use sequences and a regular number field.
    Isn't that SQL standard AGT (A Good Thing (tm))? Darn vendor specific variations and extensions ...

    kind regards,

    Jos

  11. #11
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by Stephen Douglas View Post
    and the only available types that i see in the netbeans are
    NUMERIC , FLOAT, VARCHAR2, REAL, DATE, INTEGER, CHAR, SMALLINT, DECIMAL, INT, BLOB.
    please help.

    that's enough. in java use new java.util.Date().getTime() for your timestamp-field in the database, see the example here Insert TIMESTAMP value : Date Time Timestamp**Database**Java Tutorial
    Last edited by j2me64; 04-08-2010 at 08:35 PM.

  12. #12
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    see the example here Insert TIMESTAMP value : Date Time Timestamp**Database**Java Tutorial
    thnx for such a wonderful link.. this is what i was actually looking for.thnx once again :)
    The Quieter you become the more you are able to hear !

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Stephen Douglas View Post
    thnx for such a wonderful link.. this is what i was actually looking for.thnx once again :)
    Also (re)read my reply #8.

    kind regards,

    Jos

  14. #14
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Also (re)read my reply #8.
    I got your point too as well. thnx for your concerns :)
    The Quieter you become the more you are able to hear !

Similar Threads

  1. image insertion into database
    By abhiN in forum JDBC
    Replies: 4
    Last Post: 01-05-2009, 05:09 AM
  2. Regarding Data Insertion
    By adeeb in forum JDBC
    Replies: 1
    Last Post: 06-22-2008, 05:26 AM
  3. database insertion
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 01-17-2008, 07:24 AM
  4. How to accurately test if timezone data is updated?
    By Santhosh in forum Advanced Java
    Replies: 0
    Last Post: 11-14-2007, 06:53 AM
  5. Replies: 0
    Last Post: 11-06-2007, 02:16 PM

Posting Permissions

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