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
  • 64,776
  • 13
  • 121
  • 163
Vik
  • 7,983
  • 25
  • 77
  • 154
  • 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
  • 64,776
  • 13
  • 121
  • 163
BValluri
  • 866
  • 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
  • 5,467
  • 5
  • 22
  • 73
-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,257
  • 4
  • 21
  • 35