how i can create a TimeStamp from a number like: 1183450890250

HiThank you for reading my postCan some one please let me know how i can create a timestamp object from a number like that?or better to ask how i can insert this number to a timestamp field in the database.this number is created using
[300 byte] By [Legolas.wa] at [2007-11-27 9:31:37]
# 1
if your database supports it see java.sql.timestamp
cjmosea at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you for replyMy Database support timestamp what i can not do is converting this number to a timestamp object.Thanks
Legolas.wa at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 3

> My Database support timestamp what i can not do is

> converting this number to a timestamp object.

The java.sql.Timestamp class has a constructor that takes a milliseconds time value as parameter (e.g. a value returned by the java.util.Date.getTime() method)

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html

TimTheEnchantora at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 4
You don't convert it, you let the database and the jdbc driver work that out for you... just insert it into a timestamp column, and join the army of programmers against daylight savings. They're armed with pencils, and have spent the last three years upgrading there them song... Sigh!
corlettka at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 5

Thank you all for your reply.

problem is that i recieve this number as string and when i try to

create a timestamp object from it by using the following code it face problem because Long class can not handle this number

java.sql.Timestamp ts = new Timestamp(Long.getLong("1183450890250"));

System.out.println(ts.getTime());

the above code return a NPE.

When i tried to insert that number as value of timestamp field database returned another harsh error like

Cannot insert a non-null value into a timestamp column.

What should do is

recieve an string which contains a number which is equal to Date.getTime()

insert it into timestamp column of a table in sqlserver

Legolas.wa at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 6
You should use Long.parseLong instead of Long.getLong :- parseLong parses the string argument as a signed decimal long.- getLong determines the long value of the system property with the specified name.
TimTheEnchantora at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 7

import java.sql.*;

public class Test122{

public static void main(String[] args) {

java.sql.Timestamp ts = new Timestamp(Long.parseLong("1183450890250"));

System.out.println(ts);

}

}

>javac Test122.java

>java Test122

2007-07-03 04:21:30.25

jbisha at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 8
> and join the army of programmers against daylight savings.I'm in!
aniseeda at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 9
//good forum software makes the L suffix disappear - strange//java.sql.Timestamp ts = new Timestamp(1183450890250L ); java.sql.Timestamp ts = new Timestamp(1183450890250 );
BIJ001a at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 10

I have tried to do the following

java.sql.Timestamp ts = new Timestamp(Long.parseLong("1183450890250"));

and then i used

pstmt.setTimeStamp(ts);

But SQL server returned an error which indecatet that it can not store datetime into timestamp field.

It works when i change the field type to datetime but i need to use timestamp.

Any suggestion?

thanks

Legolas.wa at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 11

> You don't convert it, you let the database and the

> jdbc driver work that out for you... just insert it

> into a timestamp column, and join the army of

> programmers against daylight savings. They're armed

> with pencils, and have spent the last three years

> upgrading there them song... Sigh!

Only those not smart enough to run their database servers on UTC :)

jwentinga at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 12

> But SQL server returned an error which indecatet that it can not store

> datetime into timestamp field.

>

> It works when i change the field type to datetime but i need to use

> timestamp.

>

> Any suggestion?

A quick Google search on "SQL Server timestamp datetime" led me to the following quote from SQL Server Books Online : The SQL Server TIMESTAMP data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database.

Therefore, I guess that the data type that corresponds to a java.sql.Timestamp is probably DATETIME in SQL server.

TimTheEnchantora at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...
# 13
> > and join the army of programmers against daylight> savings.> > I'm in!programmers against daylight? Your activities can't stand the light of day?
jwentinga at 2007-7-12 22:46:50 > top of Java-index,Java Essentials,Java Programming...