db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <rick.hille...@oracle.com>
Subject Re: How to INSERT (CURRENT_DATE+7 DAYS) in apache derby
Date Mon, 29 Apr 2013 17:29:23 GMT
On 4/28/13 11:50 PM, manojkumar16 wrote:
> I am writing a default scheduler for my project and it needs to be triggered
> 7 days later the deployment of project.
> Can somebody help me writing an INSERT statement which takes (CURRENT_DATE +
> 7 days) as a value for DATE field.
>
> INSERT INTO PURGE_ACC (START_DATE, REPEAT_INTERVAL) VALUES ( *(CURRENT_DATE
> + 7 DAYS)*, 604800000);
>
> REPEAT_INTERVAL is of long type and value associated with it is 7 days.
> I am having issue in settting [START_DATE+7 days] value.
>
> --
> Thanks,
> Manoj
>
>
>
> --
> View this message in context: http://apache-database.10148.n7.nabble.com/How-to-INSERT-CURRENT-DATE-7-DAYS-in-apache-derby-tp129786.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>
Hi Manoj,

A user-defined function could help out here. Here's the java function 
you need:

public  class   z
{
     private static  final   long    MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
     public  static  java.sql.Date    sevenDaysLater()
     {
         return new java.sql.Date( System.currentTimeMillis() + 
(MILLIS_IN_DAY * 7) );
     }
}

...and here's a script which declares this function and uses it to 
insert into a table:

connect 'jdbc:derby:memory:db;create=true';

create function sevenDaysLater() returns date
language java parameter style java no sql
external name 'z.sevenDaysLater';

create table t( dateCol date );

insert into t( dateCol ) values ( sevenDaysLater() );

select * from t;

Hope this helps,
-Rick

Mime
View raw message