Get current date using JDBCTag(s): JDBC


With most DBMS, JDBC function escape sequence can be used :
SELECT {fn curdate() }   for current date
SELECT {fn curtime() }   for current hour
SELECT {fn now() }       for current date and hour
for Oracle, you add the from dual
SELECT {fn curdate() } FROM dual  for current date
SELECT {fn curtime() } FROM dual  for current hour
SELECT {fn now() }     FROM dual  for current date and hour

Example :

// for Oracle
String sql =
  "select {fn dayname ({fn now()})}," +
  "           {d '1997-05-24'}, " +
  "           {t '10:30:29' }, " +
  "           {ts '1997-05-24 10:30:29.123'}" +
  "           from dual" ;

ResultSet rs = stmt.executeQuery(sql);

while (rs.next())
   System.out.println("results: " + rs.getString(1) +
      "\n "   + rs.getString(2) +
      "\n "   + rs.getString(3) +
      "\n "   + rs.getString(4) );

blog comments powered by Disqus