0

how to get timestamp from oracle DB using JDBC? on sql i can use select sysdate from dual.

i was trying something like

ResultSet rs = <>.createPreparedStatement("select sysdate from dual");
rs.executeQuery();

while(rs.next())
  rs.get<What to write here?>
kosa
  • 65,990
  • 13
  • 130
  • 167
Vik
  • 8,721
  • 27
  • 83
  • 168
  • Did you check ResultSet javadoc? http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getTimestamp(int) – kosa Jan 27 '16 at 02:56
  • did you check this ? http://stackoverflow.com/questions/21162753/jdbc-resultset-i-need-a-getdatetime-but-there-is-only-getdate-and-gettimestamp – prasad Jan 27 '16 at 02:59

3 Answers3

2

rs.get(1) will solve the problem. otherwise give the alias name to the column and use that.

kosa
  • 65,990
  • 13
  • 130
  • 167
BValluri
  • 916
  • 1
  • 6
  • 10
1
SELECT SYSTIMESTAMP FROM DUAL;

SYSTIMESTAMP returns the system date, including fractional seconds and time zone, of the system on which the database resides. The return type is TIMESTAMP WITH TIME ZONE.

Faraz
  • 6,025
  • 5
  • 31
  • 88
-1

If the value of sysdate is an int you can use this:

  while(rs.next()){
   int sysdate= rs.getInt("sysdate");  

But if the value of sysdate is a String you can use this:

   while(rs.next()){
   String sysdate= rs.getString("sysdate");  

For more info go to link

Abdelhak
  • 8,299
  • 4
  • 22
  • 36