Hi,
Thanks FYI Thomas. But my questions  that I have a sequence which is called 
by a function in mysql.The database has a 
table called PK_SEQUENCE  where the function will insert one an integer to 
that table and select the last updated number and return in that function 
which is called by the java code.

So what i want to know is how to convert the following function in to h2 
function.

CREATE DEFINER=`root`@`localhost` FUNCTION `PK_SEQUENCE`() RETURNS int(11)
BEGIN
DECLARE sequence_val INTEGER;
    insert into PK_SEQUENCE values (NULL);
    SELECT LAST_INSERT_ID() INTO sequence_val;
    -- delete from sequence;
    return sequence_val;
END

in the java code i call the PK_SEQUENCE function which is not a problem.

On Thursday, August 29, 2013 6:09:52 PM UTC+5:30, Thomas Mueller wrote:
>
> Hi,
>
> H2 supports sequences directly, no need to write complicated code as with 
> MySQL. See alsohttp://h2database.com/html/grammar.html#create_sequence
>
> Create a sequence:
> create sequence abc;
>
> Getting the next value:
> select next value for abc;
> or
> select abc.nextval;
>
> Regards,
> Thomas
>
>
> On Thu, Aug 29, 2013 at 1:26 PM, Rajiv Perera <[email protected]<javascript:>
> > wrote:
>
>> I am new to H2 and want help to convert the following MySql sequence to 
>> H2 sequence .
>>
>> MySql sequence:
>>
>> CREATE DEFINER=`root`@`localhost` FUNCTION `PK_SEQUENCE`() RETURNS int(11)
>> BEGIN
>> DECLARE sequence_val INTEGER;
>>     insert into PK_SEQUENCE values (NULL);
>>     SELECT LAST_INSERT_ID() INTO sequence_val;
>>     -- delete from sequence;
>>     return sequence_val;
>> END
>>
>>
>> Java method calling the sequence:
>>
>> public class PKSequenceService
>> {
>>     public static int getPKSequence(EJFrameworkConnection connection)
>>     {
>>
>>         EJStatementExecutor executor = new EJStatementExecutor();
>>         List<EJSelectResult> results = executor.executeQuery(connection, 
>> "SELECT PK_SEQUENCE() AS ID");
>>
>>         for (EJSelectResult result : results)
>>         {
>>             Object itemValue = result.getItemValue("ID");
>>             if (itemValue instanceof Integer)
>>             {
>>                 return ((Integer) itemValue).intValue();
>>             }
>>         }
>>
>>         throw new RuntimeException("Can not create PKSequence.");
>>     }
>>
>> }
>>
>> please can anyone help me convert this to H2 and Java.
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "H2 Database" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/h2-database.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to