Forums Register Login

how do I get the last day rows in mysql?

+Pie Number of slices to send: Send
hey,
i have a table in mysql DB and i want to know how can i get the rows in this table that i inserted in some specific date.
i know how how to do in Oracle but here it is something diffrent i guess. and NO I dont have column with a date attribute.

in Oracle:
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-YYYY");
Date date = new Date();
String currentDate=dateFormat.format(date);
ResultSet rsOracle=oracleStmt.executeQuery("select * from table where " +
" TRUNC(SCN_TO_TIMESTAMP(ORA_ROWSCN)) = '"+currentDate+"' ");

thanks
1
+Pie Number of slices to send: Send
ORA_ROWSCN is Oracle specific. I'm not sure MySQL has anything similar at all.

Even in Oracle, ORA_ROWSCN can behave a bit weird sometimes:
  • It cannot be used to implement optimistic locking.
  • SCNs that are farther in the past cannot even be translated to time; Oracle doesn't keep the scn to timestamp mapping forever.
  • You need to create the table with ROWDEPENDENCIES, otherwise the SCN is kept at the block level, instead of row level.

  • And if you update a row, it's ROWSCN changes, so it is not an insert date, but a last modification date.

    I would use a separate column for this even in Oracle. You can declare it default sysdate, so that your application won't even need to change the way it inserts rows. MySQL probably provides similar construct.

    (By the way, you really should use PreparedStatements.)
    I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1098 times.
    Similar Threads
    Doubt in formatting date
    string comparison with EL / JSTL
    Date
    Why they have named a calendar method like this?
    Getting date format from Locale
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Apr 16, 2024 06:22:41.