Java.sql.Timestamp( long time ) bug?
It appears to wipe milliseconds clean.
If I pass in the current time such as:
Timestamp t = new Timestamp( 1012427790890 );
and then do a
t.getTime();
it returns the correct time but with no millis:
1012427790000
It looks like Timestamp stores both millis and nanos in the nanos field (the javadoc is unclear here), so what I end up having to do is:
long seconds = timestamp.getTime();
int nanos = timestamp.getNanos();
long time = seconds + ( nanos/1000000 );
Similar Messages
-
Java.sql.Timestamp and the Epoch
Hello all
according to the JavaDoc for Timestamp, the long parameter of the constructor represents "milliseconds since January 1, 1970, 00:00:00 GMT". However, running
class Main
public static void main (String [] args)
System.out.println (new java.sql.Timestamp (0l));
} produces 1970-01-01 01:00:00.0, which is 3.6 million ms since the time stated in the doc.
My box is set to GMT. Does anyone know of an explanation for this?
CheersI'd say that extra hour is the daylight savings hour.
The GMT timezone uses it, but UTC ( Universal time coordinates ) doesn't.
regards,
Owen -
Hi all,
I'm running into this odd behaviour.
I serialize java.util.Date objects to cache and when I read them back from cache, they appear to be java.sql.Timestamp types.
I've isolated a junit test for that.
Do you know why Coherence changes the type in the middle?
Regards
Harry.
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
import com.tangosol.io.Serializer;
import com.tangosol.io.pof.ConfigurablePofContext;
import com.tangosol.util.ExternalizableHelper;
public class DatePofSerialTest {
@Test
public void testCobdate() throws Exception {
Date date=new Date();
Serializer serial = new ConfigurablePofContext();//"coherence-pof-config.xml");
Date date2=(Date)ExternalizableHelper.fromBinary(ExternalizableHelper.toBinary(date, serial), serial);
System.out.println(serial +" -- Date to serailize ["+ date.getClass() + "]");
System.out.println(serial +" -- Date from deserialize ["+ date2.getClass() + "]");
Assert.assertEquals(date, date2);/* Of course this passes, as both refer to the same time (long)*/
{code}
This gives as output
{code:title=output |borderStyle=solid}
log4j:WARN No appenders could be found for logger (Coherence).
log4j:WARN Please initialize the log4j system properly.
com.tangosol.io.pof.ConfigurablePofContext {location=coherence-pof-config.xml} -- Date to serailize [class java.util.Date]
com.tangosol.io.pof.ConfigurablePofContext {location=coherence-pof-config.xml} -- Date from deserialize [class java.sql.Timestamp]
{code}Hi Harry,
It looks like the same issue as ...
PofExtractor with java.util.Date results in ClassCastException
It was fixed in version 3.5.4.
Thanks -
PreparedStatement.setDate(new java.sql.Date(long))
Anyone knows how to set insert a Date with Time, Day, Year into a database? I have tried using the preparedStatement.setDate(new java.sql.Date(long)) but it only inserts yyyy mm dd but I want to include time too.
Anyone knows how here? Please advice.how to create an instance of Timestamp?
new java.sql.Timestamp(????)
What to put in the parameter?I think that I might have answered that in another one of your posts, if not could you elaborate your problem
http://forum.java.sun.com/thread.jsp?forum=31&thread=165123 -
How to get java.sql.Timestamp data from database
Hello, i'm new to EJB and i can't get java.sql.Timestamp data, but when i'm trying to get java.lang.String data it works fine.
* @ejb.finder
* query="SELECT OBJECT(c) FROM userSCHEMA AS c
* WHERE c.lastName LIKE ?1
* AND c.firstName LIKE ?2
* AND c.registeredDate < ?3"
* signature="java.util.Collection findPatient * (java.lang.String lastName,
* java.lang.String firstName,
* java.sql.Timestamp)"
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
<method-param>java.sql.Timestamp</method-param>
</method-params>
Where i made a mistake ?The main problem that I'm faced with, is that the
java.sql.Timestamp now has only one constructor, it
takes "long", i.e., milliseconds.That's because a Timestamp is just an offset from a particular instant of time. It doesn't have a timezone.
Please note that I'm not trying to "print", i.e., I'm
not interested in using the SimpleDateFormat.Then what are you interested in? You appear to be trying to create a Timestamp with a particular timezone, which doesn't make sense as I already noted. Is there a reason for this? -
Usage of java.sql.Timestamp with classes12.zip and ojdbc14.jar ?
Hi all,
If i'm using java.sql.Timestamp with classes12 it is functioning perfectly,
if i'm using ojdbc14 and java.sql.Timestamp it is functioning in different way and failing to do the action..
Example : update set xxx=yy where time = my Timestamp object set in Prepared statement
Hope to see the answerhttp://forum.java.sun.com/thread.jspa?threadID=460615&messageID=2116517
Timestamp insert problem
Using the "classes12.zip" file that comes with the distribution for Oracle versions 8.1.6.x and 8.1.7.x, Oracle's DATE datatype is mapped to the "java.sql.Timestamp" class. However, the "ojdbc14.jar" driver maps DATE to "java.sql.Date", and "java.sql.Date" only holds a date (without a time), whereas "java.sql.Timestamp" holds both a date and a time. -
About java.sql.Timestamp
How to add 3 hours to the time that store in java.sql.Timestamp by not using the deprecated API?
See java.util.Calendar.html#setTime(java.util.Date)
Moreover, java.sql.Timestamp extends java.util.Date -
A silly question about oracle.sql.timestamp and java.sql.timestamp
Hi,
I'm looking at a method that takes objects of type Object and does stuff if the object is really a java.sql.timestamp. If it is not then an error is flagged. In my case it flags an error when an object of type oracle.sql.timestamp is passed to it. Not really entirely comfortable with java (i'm still learning it), here's my stupid question :- why isn't oracle.sql.timestamp a subclass of java.sql.timestamp? Also in various books it indicates that java.sql.timestamp maps to oracle.sql.timestamp. Does that mean you have to physically do the mapping:
i.e.
java.sql.Timestamp t = new Timestamp( new oracle.sql.Timestamp( CURRENTTIMESTAMP ).timestampValue() );
or is there something else to it.
Thanks.
Harold.The best forum for this is probably Forum Home » Java » SQLJ/JDBC
Presumably you are refering to oracle.sql.TIMESTAMP. While this is intended to (and does) correspond to java.sql.Timestamp it can't be a subclass because it needs to be a subclass of oracle.sql.Datum. -
Convert java.sql.Timestamp to java.util.Calendar?
What's the best way to convert java.sql.Timestamp to java.util.Calendar?
Use Calendar's setTime(Date date) method.
java.sql.Timestamp extends java.util.Date.
-Roy -
ie. Is this valid?
<query>
<description>Find data between dates</description>
<query-method>
<method-name>findMetricsByDate</method-name>
<method-params>
<method-param>java.sql.Timestamp</method-param>
</method-params>
<method-params>
<method-param>java.sql.Timestamp</method-param>
</method-params>
</query-method>
<result-type-mapping>Local</result-type-mapping>
<ejb-ql>
SELECT OBJECT (o) FROM MetricResults AS o WHERE MetricResults.date > ?1 AND MetricResults.date < ?2
</ejb-ql>
</query>No. Not with current EJB 2.0 CMP specs at least. Later revisions are supposed to fix this, but for now, this seriously limits the usefulness of EJB-QL.
.P. -
How do I return a java.sql.Timestamp data type in a Web service?
I'm new to workshop and java. I'm creating a mini application to simulate a real work Web Service (development environment is on an intranet). I was able to completely simulate the Web Services minus all date values.
I'm using a standard weblogic workshop database controls that are feeding the various WebServices and their methods (Web services was generated from DB control). I get a java type not support error when I attempt to return a java.sql.Timestamp. I temporarily got around the problem by omitting all dates from the sql.
However, we are at the point where we need the complete record.
My two questions
1) What java data type do I convert the java.sql.Timestamp to
2) Where and how do I do it in workshop.
Thanks in advance
Derrick
Source view from workshop looks something like this.
public interface MyData extends DatabaseControl, com.bea.control.ControlExtension
static public class dbOverallRec
public String key;
public String field1;
public int field2;
public java.sql.Timestamp create_date
public dbOverallRec () {};
*@jc:sq; rowset-name="OverallRowSet" statement::
*select key, field1, field2 ,create_date from overall where key={KEY}::
dbOverallRec getOverallByKey(String Key);
* I had to omit the create_date to get it to workYou should try changing java.sql.Timestamp to java.util.Calendar.
java.util.Calendar maps to the dateTime type in XML Schema, and TIMESTAMP as a JDBC type.
Regards,
Mike Wooten -
Been trying to update my java for a long time now and i cannot figure it out. Have downloaded and installed it couple of times. Help would be greatly appreciated.
http://support.apple.com/kb/DL1360
-
Problem saving java.sql.timestamp
I am using java.sql.timestamps for all date fields inside the database.
the client program is using a session bean to insert the data into the database. Afterwards when I do a select in sql plus the date is always 2 hours and 30 minutes above the value I supplied to the database.
Are there any timezone settings I have to supply on the server ?
thx in advance
nullPlease shrink your code down to the bare minimum that compiles and demonstrates the problem. Do not include any tests that pass. Just the one that fails, and describe clearly exactly how it fails--what's expected and what is observed instead.
You can probably even get rid of the separate test class and just put it all in main, or at least all in the same class with main and one or a small handful of other methods. -
Java.sql.Timestamp: does not have a no-arg default constructor ERROR
Hi,
I am using jaxws(jwsdp2.0) and when i use the apt tool I get this error because I use java.sql.Timestamp as one of the fields in a class. What is the workaround for this problem? Any help is appreciated.
Thanks,
VijayI just replaced java.sql.Timestamp to java.util.Date for this to work.
Any other workaround is welcome.
Vijay -
How can I create ajava.sql.Timestamp with the value -4712.01.01?
Trying Timestamp timestamp = new Timestamp( -210863523208000l );leads to the date 4713-02-08 00:06:32.0.
Or what is the minimal java.sql.timestamp value in Java?
Edited by: bejq on 17.03.2009 08:56bejq wrote:
Thanks for your quick answer.
Yes it is 1st January 4712 BC.
Timestamp timestamp = new Timestamp( -4712, 1, 1, 0, 0, 0, 000 );//deprecated Method
System.out.println( timestamp ); // returns 2813-02-01 00:00:00.0
System.out.println( timestamp.getTime() );// returns -150904688400000Thats not what I want.You have lost me then. Unless of course you want to use SimpleDateFormat with an appropriate TZ to parse the date to a java.util.Date and then construct a java.sql.Timestamp from the java.util.Date using the java.util.Date#getTime() method to construct the java.sql.Timestamp .
Edited by: sabre150 on Mar 17, 2009 10:41 AM
Maybe you are looking for
-
I cannot send email on my iMac. I have recently updated to Yosemite. I don't know if that is the problem or not. However, I can receive email on all of my email accounts, but cannot send. It shows that my accounts are offline. How do I fix this?
-
An error occurred while trying to access the Apple Wireless Device
Hello All; I just bought an Airport Extreme Base Station today and am all ready having problems. I am running a PC. I connected a Motorola DSL model to the Airport's QAN port and then I connected the computer to one of the Ethernet ports. When I firs
-
Hi all, I am trying to tune some statements that worked fine in Oracle 9 and are a pain in Oracle 10. I have one big select (200 rows) that joins a hand full of tables (each with 80thousand or so records, one is bigger). The execution plan for this s
-
Authorization Error ( -42408 ) for iTunes / iPod
suddenly, itunes invalidated purchased tunes on ipod at the time of sync due to the use of unauthorized computer, which i've been using past years and synced the same ipod almost everyday. then, i tried to authorize my computer by typing in UserID an
-
Imac- how do I stop the messaging where I get every text on my computer?
this is driving me crazy- how do I block it- every phone text message shows up on the computer.