471,896 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

JAVA :: Timestamp from DB2

Hi,
is there any possibility to get a Timestamp in Java from the DB2-System?
(not from a table)

Thanks for help.

Andreas
Nov 12 '05 #1
5 13929
You can use SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1 in many
(all?) versions of DB2. This doesn't require access to any user tables.

Check the "SET" statement in SQL Reference V.2 (LUW).

VALUES(CURRENT TIMESTAMP) will also generate a row that has what you
want but I've never tried retrieving the row in Java.
Phil Sherman
Andreas wrote:
Hi,
is there any possibility to get a Timestamp in Java from the DB2-System?
(not from a table)

Thanks for help.

Andreas


Nov 12 '05 #2

"Andreas" <di************@handshake.de> wrote in message
news:9c**************************@posting.google.c om...
Hi,
is there any possibility to get a Timestamp in Java from the DB2-System?
(not from a table)

The following code will work, assuming you have already instantiated the
connection, named parmConn in this case:

ResultSet rs = null;

Statement stmt = null;

/* Get the current timestamp. */

try {

String query = "Values(current timestamp)";

stmt = parmConn.createStatement();

rs = stmt.executeQuery(query);
System.out.println("");

System.out.print(query + ": ");

while (rs.next()) {

System.out.print(rs.getTimestamp(1)); //display timestamp

System.out.println("");

}

stmt.close();

rs.close();

}

catch (SQLException sql_excp) {

sql_excp.printStackTrace();

}

The output I got when I ran it was:

Values(current timestamp): 2004-10-19 12:13:11.901

Rhino
Nov 12 '05 #3

The output I got when I ran it was:

Values(current timestamp): 2004-10-19 12:13:11.901

Sorry, that wasn't the best example of output. Normally, the fractional part
of the seconds would be six digits, not 3. I just happened to run that query
at exactly 12:13:11 and 901 microseconds. Here is a more typical output:

Values(current timestamp): 2004-10-19 14:39:57.283002

Rhino
Nov 12 '05 #4
Hi,
thank You very much for the fast help.

I'll try it asap (at the moment I haven't access to the DB2-System)... ;-)

Andreas
Nov 12 '05 #5

"Andreas" <di************@handshake.de> wrote in message
news:9c**************************@posting.google.c om...
Hi,
thank You very much for the fast help.
My pleasure!
I'll try it asap (at the moment I haven't access to the DB2-System)... ;-)

Rhino
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Roberto Nenni | last post: by
reply views Thread by Michael Welp | last post: by
2 posts views Thread by Kent Lewandowski | last post: by
6 posts views Thread by tak | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.