title: How can I get the current date/time from a DB server via JDBC, regardless of DB vendor?
body: <p>I'd like to be able to get the current date/time (timestamp) from the DB sever I have a Connection to, regardless of the DB. (Ideally, I'd like something that works for Oracle, DB2, SQL Server, and Postgres).</p>
  
  <p>Searching the internet, I've seen allusions to the LOCALTIMESTAMP function and to NOW() and to CURRENT_TIMESTAMP, but I've seen no clarity as to whether any of these truly works in an interoperable fashion across RDBMSes.</p>
  
  <p>I'm willing to code up alternatives for different DBs if necessary, but haven't even seen any clarity on the best way to do this for the individual DB vendors. And surely if it needs to be done differently for each there must be some Java library that wraps JDBC connections and does this?</p>
  
  <p>Aside from figuring out which SQL function to use, I'm also wondering if there's a standard way to do a SQL query that is just a function invocation -- some DBs seem to support</p>
  
  <pre><code>SELECT fn();
  </code></pre>
  
  <p>...but Oracle seems to require adding</p>
  
  <pre><code>...FROM DUAL;
  </code></pre>
  
  <p>I know that the SQL "standard" is a bit dodgy, but I wondered if anyone who has more experience than me with working across databases and with JDBC and related libraries might be able to point me in the right direction.</p>
  
  <p>thanks!</p>