If you are using Spring, you can init H2 using the jdbc:embedded-database
element and then use jdbc:script property

More here:
http://stackoverflow.com/questions/7968067/startup-script-to-create-a-schema-in-hsqldb

On Tue, May 8, 2012 at 10:50 PM, Luigi R. Viggiano <[email protected]
> wrote:

> Hello everybody.
>
> The feature to execute SQL on connection is an innovative idea.
> Especially because the RUNSCRIPT can take a URL and can read the
> script from the classpath.
>
> But for my embedded application, what I need to do is to have a
> feature that I would call "Execute SQL on Database Creation": not on
> every connection but just if the database is created anew. So, when my
> application starts for the first time, it will connect and silently
> create the database *and the schema*.
> I think it would be really useful. Is this already available? Or, does
> it makes sense for a feature request?
>
> At the moment, I think I will do something like:
>
> "show tables" and, if returns 0 recs I'll do a "runscript
> classpath:foo/bar/baz.sql"
>
> or moving the above logic into stored procedure, and connecting using:
>
> jdbc:h2:file:~/sample;INIT=CREATE ALIAS IF NOT EXISTS MAKE_SCHEMA FOR
> "com.myApp.Function.makeSchema"; CALL MAKE_SCHEMA();
>
> it could work, right? :-)
>
> Thanks.
> Luigi
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>
>


-- 
   Vasile Rotaru

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to