473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 14005
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
I am forced to have to compare the value of some PHP timestamp with a Java-based java.util.Date.getTime() timestamp. Let me show you how they look: The Java time is returned to the PHP...
1
by: Roberto Nenni | last post by:
hi all and sorry for my english I write into a SqlServer2000 database via jdbc using a PreparedStatement (pstmt) and one of fields is a TimeStamp, my code is: qwdum=System.currentTimeMillis();...
0
by: Michael Welp | last post by:
Hallo NG, i have a problem with a Timestamp field. I use a JDBC Type 4 - Driver. When i make a select on a table with a timestamp-field i got for example the result : 2004-04-30 15:23:44.0 ...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
2
by: Chris | last post by:
Hi, I seem to be having some problems connecting to webservices. I'm running a C# client connected to a Java webservice using GLUE. The difference between the two request and response pairs...
1
by: keyjen2017 | last post by:
i am trying to read the table in DB2 using JAVA code. then it is supposed to be copied in .txt file. how can i do this? other thing, i m passing date in dddd-mm-yy format from JAVA codeto call a ...
2
ruch095
by: ruch095 | last post by:
i'm student and my project work about RTP Protocol (Develop with java),now i want a algorithm for calculate NTP timestamp(header of rtcp protocol).Anybody who have this algorithm,please tell me. ...
6
by: tak | last post by:
Hi. I have a client / server application, which the client will send the server a timestamp everytime when there is a transaction. The client is using Java, and it sends the timestamp using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.