Vik
Vik

Reputation: 9289

how to get timestamp from oracle DB using jdbc

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?>

Upvotes: 0

Views: 1587

Answers (3)

Abdelhak
Abdelhak

Reputation: 8387

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

Upvotes: -1

Faraz
Faraz

Reputation: 6265

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.

Upvotes: 1

BValluri
BValluri

Reputation: 956

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

Upvotes: 2

Related Questions