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

Similar Messages

  • 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 work

    You 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

  • 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

  • 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,
    Vijay

    I just replaced java.sql.Timestamp to java.util.Date for this to work.
    Any other workaround is welcome.
    Vijay

  • Java.sql.Date vs java.util.Date vs. java.util.Calendar

    All I want to do is create a java.sql.Date subclass which has the Date(String) constructor, some checks for values and a few other additional methods and that avoids deprecation warnings/errors.
    I am trying to write a wrapper for the java.sql.Date class that would allow a user to create a Date object using the methods:
    Date date1 = new Date(2003, 10, 7);ORDate date2 = new Date("2003-10-07");I am creating classes that mimic MySQL (and eventually other databases) column types in order to allow for data checking since MySQL does not force checks or throw errors as, say, Oracle can be set up to do. All the types EXCEPT the Date, Datetime, Timestamp and Time types for MySQL map nicely to and from java.sql.* objects through wrappers of one sort or another.
    Unfortunately, java.sql.Date, java.sql.Timestamp, java.sql.Time are not so friendly and very confusing.
    One of my problems is that new java.sql.Date(int,int,int); and new java.util.Date(int,int,int); are both deprecated, so if I use them, I get deprecation warnings (errors) on compile.
    Example:
    public class Date extends java.sql.Date implements RangedColumn {
      public static final String RANGE = "FROM '1000-01-01' to '8099-12-31'";
      public static final String TYPE = "DATE";
       * Minimum date allowed by <strong>MySQL</strong>. NOTE: This is a MySQL
       * limitation. Java allows dates from '0000-01-01' while MySQL only supports
       * dates from '1000-01-01'.
      public static final Date MIN_DATE = new Date(1000 + 1900,1,1);
       * Maximum date allowed by <strong>Java</strong>. NOTE: This is a Java limitation, not a MySQL
       * limitation. MySQL allows dates up to '9999-12-31' while Java only supports
       * dates to '8099-12-31'.
      public static final Date MAX_DATE = new Date(8099 + 1900,12,31);
      protected int _precision = 0;
      private java.sql.Date _date = null;
      public Date(int year, int month, int date) {
        // Deprecated, so I get deprecation warnings from the next line:
        super(year,month,date);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public Date(String s) {
        super(0l);
        // Start Cut-and-paste from java.sql.Date.valueOf(String s)
        int year;
        int month;
        int day;
        int firstDash;
        int secondDash;
        if (s == null) throw new java.lang.IllegalArgumentException();
        firstDash = s.indexOf('-');
        secondDash = s.indexOf('-', firstDash+1);
        if ((firstDash > 0) & (secondDash > 0) & (secondDash < s.length()-1)) {
          year = Integer.parseInt(s.substring(0, firstDash)) - 1900;
          month = Integer.parseInt(s.substring(firstDash+1, secondDash)) - 1;
          day = Integer.parseInt(s.substring(secondDash+1));
        } else {
          throw new java.lang.IllegalArgumentException();
        // End Cut-and-paste from java.sql.Date.valueOf(String s)
        // Next three lines are deprecated, causing warnings.
        this.setYear(year);
        this.setMonth(month);
        this.setDate(day);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public static boolean isWithinRange(Date date) {
        if(date.before(MIN_DATE))
          return false;
        if(date.after(MAX_DATE))
          return false;
        return true;
      public String getRange() { return RANGE; }
      public int getPrecision() { return _precision; }
      public String getType() { return TYPE; }
    }This works well, but it's deprecated. I don't see how I can use a java.util.Calendar object in stead without either essentially re-writing java.sql.Date almost entirely or losing the ability to be able to use java.sql.PreparedStatement.get[set]Date(int pos, java.sql.Date date);
    So at this point, I am at a loss.
    The deprecation documentation for constructor new Date(int,int,int)says "instead use the constructor Date(long date)", which I can't do unless I do a bunch of expensive String -> [Calendar/Date] -> Milliseconds conversions, and then I can't use "super()", so I'm back to re-writing the class again.
    I can't use setters like java.sql.Date.setYear(int) or java.util.setMonth(int) because they are deprecated too: "replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date)". Well GREAT, I can't go from a Date object to a Calendar object, so how am I supposed to use the "Calendar.set(...)" method!?!? From where I'm sitting, this whole Date deprecation thing seems like a step backward not forward, especially in the java.sql.* realm.
    To prove my point, the non-deprecated method java.sql.Date.valueOf(String) USES the DEPRECATED constructor java.util.Date(int,int,int).
    So, how do I create a java.sql.Date subclass which has the Date(String) constructor that avoids deprecation warnings/errors?
    That's all I really want.
    HELP!

    I appreciate your help, but what I was hoping to accomplish was to have two constructors for my java.sql.Date subclass, one that took (int,int,int) and one that took ("yyyy-MM-dd"). From what I gather from your answers, you don't think it's possible. I would have to have a static instantiator method like:public static java.sql.Date createDate (int year, int month, int date) { ... } OR public static java.sql.Date createDate (String dateString) { ... }Is that correct?
    If it is, I have to go back to the drawing board since it breaks my constructor paradigm for all of my 20 or so other MySQL column objects and, well, that's not acceptable, so I might just keep my deprecations for now.
    -G

  • Java.util.Date badly serialized to java.sql.Timestamp Coherence 3.5.2

    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

  • Convert java.sql.Date to java.util.Date

    How do i convert a java.sql.Date to java.util.Date ?
    SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yy HH:mm");
    Date received=myresultset.getDate(1);
    String utildate = formatter.format(received);
    <%=utildate%>
    Result : doesn't keep the HH:mm format
    14/03/04 00:00
    Ideas ?

    There is simple way to do this job...
    java.util.Date utilDate = new java.util.Date();
    java.sql.Data sqlDate = new java.sql.Date(utilDate.getTime())
    Enjoy Coding ! ! ! ! !

  • Java.sql.Timestamp creation with value -4712.01.01 (oracle min timestamp)

    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:56

    bejq 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

  • 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?

  • RQL Error - JQuery Datepicker and java.sql.Timestamp

    Hello everyone,
    I am using JQuery Datepicker to select start and end date range.
    Both start date and end date are successfully passed as like this. 10/01/2013 and 10/31/2013
    It has java.sql.Timestamp mapping in both startDate and endDate.
    Property name in component browser is transactionTimestamp.
    It gives me following error when i passed both parameters.
    <dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
        <dsp:param name="repository" value="/atg/commerce/order/OrderRepository" />
        <dsp:param name="itemDescriptor" value="inStorePaymentStatus" />
        <dsp:param name="queryRQL" value="transactionTimestamp>=:startDate AND transactionTimestamp<:endDate" />
    **** Error    Wed Oct 02 16:07:21 IST 2013    1380710241490    /atg/dynamo/droplet/RQLQueryForEach    unable to parse/execute query due to RepositoryException    CONTAINER:atg.repository.RepositoryException; SOURCE:java.sql.SQLException: java.sql.SQLDataException: ORA-01843: not a valid month
    It gives NO error when i passed single parameter.
      <dsp:param name="queryRQL" value="transactionTimestamp>=:startDate"/>
    can anyone suggest me a solution.
    Thanks
    saminda konkaduwa

    Hi all,
    Found the solution. We have to use parameter converter tools as well. that is the additional parameter called "date" where we passed date format.
    <dsp:param name="startDate" param="10/12/2012" date="MM/dd/yyyy"/>
    <dsp:param name="endDate" param="10/12/2015" date="MM/dd/yyyy"/>
    Explanation :
    JSP FILE ( testing.jsp)
    =================
    <dsp:page>
    <head>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript" src="merchant_portal_ajax_agent_report.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#startDate").datepicker();
        $(function() {
            $("#endDate").datepicker();
    </script>
    </head>
    <body>
    <table>
                        <tr>
                            <td>Start Date</td>
                            <td><input type="text" id="startDate" class="picker" name="sDate" /></td>
                            <td>End Date</td>
                            <td><input type="text" id="endDate" class="picker" name="sDate" /></td>
                            <td><input value="Find" type="submit" class="atg_button" onclick="loadAgentReport()" /></td>                       
                        </tr>
                        <tr>
                                    <div id="agentReportTable"></div>
                        </tr>
    </table>
    </body>
    </dsp:page>
    JAVA SCRIPT FILE (merchant_portal_ajax_agent_report.js)
    ============================================
    function loadAgentReport() {
        var startDateValue = $("#startDate").val();
        var endDateValue = $("#endDate").val();
            $(document).ready(function() {
              $.ajax({
                    type : "POST",
                    url : "merchant_portal_view_agent_report.jsp",
                    data : {
                       startDate : "" + startDateValue + "" , endDate : "" + endDateValue + ""
                    success : function(result) {
                        $("#agentReportTable").html("");
                        $("#agentReportTable").html(result);
    JSP File ( This invoked by Jquery ) merchant_portal_view_agent_report.jsp
    =======================================================
    <dsp:page>
                                <dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
                                    <dsp:param name="repository" value="/atg/commerce/order/OrderRepository" />
                                    <dsp:param name="itemDescriptor" value="inStorePaymentStatus" />
                                    <dsp:param name="queryRQL" value="agentId=:agentId AND transactionTimestamp>:startDate AND transactionTimestamp<:endDate" />
                                    <dsp:oparam name="output">
                                       <dsp:valueof param="element.transactionId"/>  <dsp:valueof param="element.transactionStatus"/>
        </br> 
                                    </dsp:oparam>
                                    <dsp:oparam name="empty">
                                             No data found
                                   </dsp:oparam>
                               </dsp:droplet>
    </dsp:page>
    Thanks
    saminda konkaduwa

  • 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?
    Cheers

    I'd say that extra hour is the daylight savings hour.
    The GMT timezone uses it, but UTC ( Universal time coordinates ) doesn't.
    regards,
    Owen

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

  • 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 answer

    http://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.

  • Can I use ' ', ' ', '= ' and ' =' with java.sql.Timestamp objects in EJB-QL

    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.

  • 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
    null

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

Maybe you are looking for

  • Script Error when I try to Preview a report

    Dear Experts, I have this issue when I try do a open a report by clicking Preview in CMC,  I get a parameter screen where I have to plug the values. When I try to click on the calendar icon to pick up the dates I get this error message: Internet Expl

  • How do I get Genius to work with music it should?

    How do I start a Genius playlist with Cold War Kids - Hang Me Up To Dry? There is no reason it shouldn't work, it's not like I don't have a lot of similar music. In my google search of the issue, many Genius playlists that people have posted included

  • ATV w/ AE & no internet in RV, Airplay issue...

    I have been reading and found that I can use Apple TV and an Airport Express to create a Local network in my RV to connect iOS devices to Apple TV. A lot of the campgrounds we frequent have strong cell (4G) but no internet. My goal would be able to s

  • [DW-8]No me funciona la funcion captcha

    Hola, estoy probando poniendo captcha en mi web, pero estoy haciendo pruebas y no me funciona, lo que hago es el en form, es llamar a una funcion Comprobar que tiene en esa misma pagina, pero no me funciona, os pongo el codigo asi se ve mejor <body>

  • Setting background colour to transparent?

    Why does cropping a photo leave a green background instead of being transparent? I'm fairly new at using the Photo Elements 10, I had v.7 which I could select "reverse" and delete background, then copy and paste into a new picture. However, the "copy