Results 1 to 6 of 6
  1. #1
    chyeeqi is offline Member
    Join Date
    Aug 2009
    Posts
    23
    Rep Power
    0

    Default how can i take 1st record from database??

    how can i take 1st record from database??
    i had try tis way
    Java Code:
    rsS = stmtS.executeQuery("SELECT * FROM Reception");
            if( rsS.next());
             {
            Rec_Name.setText(rsS.getString(1));
            }
    but i get the last record in the databse, how can i get the 1st record

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    There's no such thing as the "first record"...unless you put an "order by" in the query.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Google "<Your database name> rownum"

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    Still won't matter.
    rownum is (usually) simply a tag onto a query. It's not a physical thing.
    Consequently, as I said, the concept of "first record" is meaningless without an order by...there's no guarantee (in SQL) that you'll get the rows back in the same order for the next time you run the query.

    So the OP needs to figure out why, exactly, the result returned by the db was wrong.

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    Hi,
    You can use scrollable ResultSet....u can set the pointer to first record using

    first() in ResultSet and then u can retreive.
    -Regards
    Ramya
    Ramya:cool:

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    Which, first off, will return the same record that the first call to next() returns, which is apparently the wrong record, and secondly does not alter the fact that, once again, without an order by the question is meaningless.

Similar Threads

  1. Record Button
    By nicezam in forum NetBeans
    Replies: 3
    Last Post: 04-27-2009, 03:53 AM
  2. pointing to 1st record in a file
    By swati.jyoti in forum New To Java
    Replies: 1
    Last Post: 04-25-2009, 08:38 AM
  3. how to delete record from db using jsp
    By Manas Das in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-31-2009, 07:36 PM
  4. Can't record sound
    By bozovilla in forum Java Applets
    Replies: 12
    Last Post: 08-04-2008, 03:57 PM
  5. selecting a record in database
    By ramachandran in forum New To Java
    Replies: 0
    Last Post: 10-25-2007, 07:06 AM

Posting Permissions

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