how can i connect to h2 console with no need of shutdown the tomcat server?

774 views
Skip to first unread message

Ro

unread,
Aug 8, 2008, 2:55:05 AM8/8/08
to H2 Database
hi all,
i am running my web application in tomcat server. And by using
this web application i have connected to h2 database and inserted the
data. but when i trying to start the web browser by using http://localhost:8082
i came to know that h2 database is not yet started. So i started the
h2 database by using the h2.bat file. Now i am able to open the link
http://localhost:8082 . But when i am trying to connect, it is giving
the following error

Database may be already in use: Locked by another process. Possible
solutions: close all other connection(s); use the server mode
[90020-76] 90020/90020 (Help)


If i shutdown the tomcat server then i am not getting above error. How
can i solve this problem.
I am posting my code also. just look at this. And give me a gud
suggestion to connect to h2 console(http://localhost:8082) with out
need of shutdown tomcat server.

1) database connection program:---------------------------
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/
test", "sa", "");
Statement st = null;
st = conn.createStatement();
int i = st.executeUpdate("INSERT INTO TEST VALUES(10,
'Hello')");
st.close();
conn.close();




2) copied h2.jar file to my application's lib folder
3) web.xml file of my web application

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed
with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version
2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>


<!-- Define servlet-mapped and path-mapped example filters -->
<filter>
<filter-name>Servlet Mapped Filter</filter-name>
<filter-class>filters.ExampleFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>filters.ExampleFilter.SERVLET_MAPPED</param-value>
</init-param>
</filter>
<filter>
<filter-name>Path Mapped Filter</filter-name>
<filter-class>filters.ExampleFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>filters.ExampleFilter.PATH_MAPPED</param-value>
</init-param>
</filter>
<filter>
<filter-name>Request Dumper Filter</filter-name>
<filter-class>filters.RequestDumperFilter</filter-class>
</filter>

<!-- Example filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-
class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC_JP</param-value>
</init-param>
</filter>

<filter>
<filter-name>Compression Filter</filter-name>
<filter-class>compressionFilters.CompressionFilter</filter-
class>

<init-param>
<param-name>compressionThreshold</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
</filter>

<!-- Define filter mappings for the defined filters -->
<filter-mapping>
<filter-name>Servlet Mapped Filter</filter-name>
<servlet-name>invoker</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Path Mapped Filter</filter-name>
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>

<!-- Example filter mapping to apply the "Set Character Encoding"
filter
to *all* requests processed by this web application -->
<!--
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->

<!--
<filter-mapping>
<filter-name>Compression Filter</filter-name>
<url-pattern>/CompressionTest</url-pattern>
</filter-mapping>
-->

<!--
<filter-mapping>
<filter-name>Request Dumper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->

<!-- Define example application events listeners -->
<listener>
<listener-class>listeners.ContextListener</listener-class>
</listener>
<listener>
<listener-class>org.h2.server.web.DbStarter</listener-class>
</listener>
<listener>
<listener-class>listeners.SessionListener</listener-class>
</listener>

<!-- Define servlets that are included in the example application
-->

<servlet>
<servlet-name>servletToJsp</servlet-name>
<servlet-class>servletToJsp</servlet-class>
</servlet>
<servlet>
<servlet-name>ChatServlet</servlet-name>
<servlet-class>chat.ChatServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>CompressionFilterTestServlet</servlet-name>
<servlet-
class>compressionFilters.CompressionFilterTestServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>
<servlet>
<servlet-name>RequestInfoExample</servlet-name>
<servlet-class>RequestInfoExample</servlet-class>
</servlet>
<servlet>
<servlet-name>RequestHeaderExample</servlet-name>
<servlet-class>RequestHeaderExample</servlet-class>
</servlet>
<servlet>
<servlet-name>RequestParamExample</servlet-name>
<servlet-class>RequestParamExample</servlet-class>
</servlet>
<servlet>
<servlet-name>CookieExample</servlet-name>
<servlet-class>CookieExample</servlet-class>
</servlet>
<servlet>
<servlet-name>SessionExample</servlet-name>
<servlet-class>SessionExample</servlet-class>
</servlet>
<servlet>
<servlet-name>UserController</servlet-name>
<servlet-class>UserController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserController</servlet-name>
<url-pattern>/UserController</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ChatServlet</servlet-name>
<url-pattern>/jsp/chat/chat</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CompressionFilterTestServlet</servlet-name>
<url-pattern>/CompressionTest</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlets/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RequestInfoExample</servlet-name>
<url-pattern>/servlets/servlet/RequestInfoExample/*</url-
pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RequestHeaderExample</servlet-name>
<url-pattern>/servlets/servlet/RequestHeaderExample</url-
pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RequestParamExample</servlet-name>
<url-pattern>/servlets/servlet/RequestParamExample</url-
pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CookieExample</servlet-name>
<url-pattern>/servlets/servlet/CookieExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SessionExample</servlet-name>
<url-pattern>/servlets/servlet/SessionExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>servletToJsp</servlet-name>
<url-pattern>/servletToJsp</url-pattern>
</servlet-mapping>

<jsp-config>
<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/debug-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/debug-taglib.tld
</taglib-location>
</taglib>

<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/examples-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/example-taglib.tld
</taglib-location>
</taglib>

<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/jsp2-example-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp2/jsp2-example-taglib.tld
</taglib-location>
</taglib>

<jsp-property-group>
<description>
Special property group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>/jsp2/misc/config.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>ISO-8859-1</page-encoding>
<scripting-invalid>true</scripting-invalid>
<include-prelude>/jsp2/misc/prelude.jspf</include-prelude>
<include-coda>/jsp2/misc/coda.jspf</include-coda>
</jsp-property-group>
</jsp-config>

<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/security/protected/*</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area
-->
<role-name>tomcat</role-name>
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>

<!-- Default login configuration uses form-based authentication --
>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Example Form-Based Authentication Area</realm-name>
<form-login-config>
<form-login-page>/jsp/security/protected/login.jsp</form-login-
page>
<form-error-page>/jsp/security/protected/error.jsp</form-error-
page>
</form-login-config>
</login-config>

<!-- Security roles referenced by this web application -->
<security-role>
<role-name>role1</role-name>
</security-role>
<security-role>
<role-name>tomcat</role-name>
</security-role>

<!-- Environment entry examples -->
<!--env-entry>
<env-entry-description>
The maximum number of tax exemptions allowed to be set.
</env-entry-description>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry-->
<env-entry>
<env-entry-name>minExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/name1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>value1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/bar/name2</env-entry-name>
<env-entry-type>java.lang.Boolean</env-entry-type>
<env-entry-value>true</env-entry-value>
</env-entry>


</web-app>



Thomas Mueller

unread,
Aug 9, 2008, 11:12:27 AM8/9/08
to h2-da...@googlegroups.com
Hi,

> i am running my web application in tomcat server. And by using
> this web application i have connected to h2 database and inserted the
> data. but when i trying to start the web browser by using http://localhost:8082
> i came to know that h2 database is not yet started. So i started the
> h2 database by using the h2.bat file. Now i am able to open the link
> http://localhost:8082 . But when i am trying to connect, it is giving
> the following error
>
> Database may be already in use: Locked by another process. Possible
> solutions: close all other connection(s); use the server mode
> [90020-76] 90020/90020 (Help)
>
>
> If i shutdown the tomcat server then i am not getting above error.

The problem is, you can not open the database in embedded mode from
two processes at the same time.

You need to use the server mode, or you need to start the H2 Console
from within your web application.

See also:
http://www.h2database.com/html/features.html#connection_modes
http://www.h2database.com/html/tutorial.html#web_applications
http://www.h2database.com/html/tutorial.html#using_server

Regards,
Thomas

Ro

unread,
Aug 10, 2008, 2:06:54 AM8/10/08
to H2 Database
Hi thomas,

I think i have started my H2 console in server mode only.
In the H2 documentation, they excplained to add a listener in the
web.xml file.
If you see my web.xml, I have added the listener in the web.xml file.

<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>
<listener>
<listener-class>org.h2.server.web.DbStarter</listener-class>
</listener>

<!-- Define servlet-mapped and path-mapped example filters -->
<filter>
<filter-name>Servlet Mapped Filter</filter-name>
<filter-class>filters.ExampleFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>filters.ExampleFilter.SERVLET_MAPPED</param-
value>
</init-param>
</filter>
So plz check this one and tell me what might be the problem. Can
you plz reply to me fast. then i can go a head...


On Aug 9, 8:12 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> >      i am running my web application in tomcat server. And by using
> > this web application i have connected to h2 database and inserted the
> > data. but when i trying to start the web browser by usinghttp://localhost:8082
> > i came to know that h2 database is not yet started. So i started the
> > h2 database by using the h2.bat file. Now i am able to open the link
> >http://localhost:8082. But when i am trying to connect, it is giving

Thomas Mueller

unread,
Aug 12, 2008, 9:39:35 PM8/12/08
to h2-da...@googlegroups.com
Hi,

> I think i have started my H2 console in server mode only.

The most simple solution (if you need to access the same database from
multiple processes) is to start the server (start h2.bat), and connect
to the database in server mode everywhere. There is a faster solution
(the mixed mode), but I wouldn't suggest to try that as it is more
complicated. For more information about the server mode, see
http://www.h2database.com/html/tutorial.html#using_server

In your case, I suggest to change the database URL to
jdbc:h2:tcp://localhost/C:/data/h2/test everywhere. You don't need the
DbStarter servlet any more, but you need to start the server by
running h2.bat.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages