from DBStarter.java lines 33-40:
            // This will get the setting from a context-param in web.xml if
defined:
            ServletContext servletContext =
servletContextEvent.getServletContext();
            String url = getParameter(servletContext, "db.url",
"jdbc:h2:~/test");
            String user = getParameter(servletContext, "db.user", "sa");
            String password = getParameter(servletContext, "db.password",
"sa");

            conn = DriverManager.getConnection(url, user, password);

This code gives you an embedded connection.
1) get servlet context
2) get connection parameters from context
3) pass connection parameters to jdbc DriverManager to get a connection.
The URL for an embedded database looks like "jdbc:h2:~/test" (
http://h2database.com/html/faq.html#connect)

2009/3/4 Lukas Zapletal <[email protected]>

>
> Using the context attribute.
>
> LZ
>
> On 4 Bře, 12:20, Lukas Zapletal <[email protected]> wrote:
> > Hello,
> >
> > I cannot find any kind of information how to connect to the Server
> > Mode in a web application. The documentation says "For details on how
> > to access the database, see the code DbStarter.java" but its no
> > information there.
> >
> > http://www.h2database.com/html/tutorial.html#web_applications
> >
> > I can find only this in the source code:
> >
> >             // To access the database in server mode, use the database
> > URL:
> >             // jdbc:h2:tcp://localhost/~/test
> >
> > But I would like to use embedded mode without TCP. How to get
> > connections in my web app? From the context?
> >
> > Thanks
> >
>

--~--~---------~--~----~------------~-------~--~----~
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