H2创建内存数据库服务器,并启动Web控制台
写HelloWorld的方便工具。依靠初始化脚本,数据随时重置。交流起来,也方便。
maven
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.194</version>
</dependency>
web.xml中配置
<context-param>
<param-name>db.url</param-name>
<param-value>jdbc:h2:mem:test</param-value>
</context-param>
<context-param>
<param-name>db.user</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.password</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>db.tcpServer</param-name>
<param-value>-tcpAllowOthers</param-value>
</context-param>
<listener>
<listener-class>org.h2.server.web.DbStarter</listener-class>
</listener>
<servlet>
<servlet-name>H2Console</servlet-name>
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
<init-param><param-name>webAllowOthers</param-name><param-value></param-value></init-param>
<init-param><param-name>trace</param-name><param-value></param-value></init-param>
</servlet>
<servlet-mapping>
<servlet-name>H2Console</servlet-name>
<url-pattern>/h2/*</url-pattern>
</servlet-mapping>