By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

JAVA :: Timestamp from DB2

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

"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

P: n/a

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

P: n/a
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

P: n/a

"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.