package com.hsqldb.dbfilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.hsqldb.Server;
public class DBRunListener implements ServletContextListener{
private static Server server;
@Override
public void contextDestroyed(ServletContextEvent arg0) {
new Thread(){
public void run() {
server.shutdown();
}
}.start();
}
@Override
public void contextInitialized(ServletContextEvent config) {
String filepath = config.getServletContext().getRealPath(config.getServletContext().getInitParameter("DBpropertyFile"));
Properties p = new Properties();
try {
p.load(new FileInputStream(filepath));
} catch (FileNotFoundException e) {
System.out.println(filepath +" not found");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String dbpath = p.getProperty("dbpath");
String dbname = p.getProperty("dbname");
String dbport = p.getProperty("dbport");
server = new Server();
server.setDatabasePath(0, dbpath);
server.setDatabaseName(0, dbname);
server.setPort(Integer.valueOf(dbport));
//设置控制台不打印输出
//server.setSilent(true);
//server.setTrace(false);
new Thread() {
public void run() {
server.start();
}
}.start();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>HSQLDB</display-name>
<listener>
</listener>
<listener>
<!-- 初始化LOG4J -->
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
<!-- 启动HSQLDB数据库 -->
<listener-class>com.hsqldb.dbfilter.DBRunListener</listener-class>
<!-- 加载Spring容器配置 -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 设置数据库配置文件路径 -->
<context-param>
<param-name>DBpropertyFile</param-name>
<param-value>WEB-INF/db.properties</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
WEB-INF/db.properties;
dbpath=D:\workspace\HSQLDB\WebContent\WEB-INF\lib
dbname=mydb
dbport=9999
driver=org.hsqldb.jdbcDriver
url=jdbc:hsqldb:hsql://localhost:9999/mydb
username=sa
password=
分享到:
相关推荐
hsqldb确实是个好东西,对于系统演示,开发等都很方便。
hsqldb 2 3 2 zip HyperSQL是用Java编写的一款SQL关系数据库引擎 它的核心完全是多线程的 支持双向锁和MVCC 多版本并发控制 几乎完整支持ANSI 92 SQL 支持常见数据类型 最新版本增加了对BLOB和CLOB数据的支持 最高...
简单的创建两个例子,如何创建hsqldb,如何使用hsqldb查询数据等。
hsqldb jdbc driver适合于hsqldb
hsqldb数据库下载,很好用,简易的内存数据库,特别适合初学者。
hsqldb的最新1.9.0版本,支持windows操作系统
HSQLDB中文文档,能够提高数据的处理速度。
数据库连接 hsqldb1.7.1.jar
hsqldb可能需要的额外jar包 Additional Jar files needed for hsqldb.
开源数据库hsqldb最新版本2.5.0,含源代码及bin文件 Open-sourced database hsqldb2.5.0, including source code and bin file(stuctured in form of .BAT)
Hsqldb是一个开放源代码的JAVA数据库,其具有标准的SQL语法和JAVA接口,它可以自由使用和分发,非常简洁和快速。
hsqldb source code and document, it is the version 2.0 rc3. sqldb是一个非常著名的数据库,支持嵌入和client-server方式,支持内存模式,cached, text 3种表。 欢迎更多人研究这种优秀的开源数据库
里面有hsqldb_1_8_0_10.zip 还有个hsqldb-mini.zip 包括一个hsqldb学习文档
HSQLDB的安装,使用,以及简单的例子讲解
hsqldb-2.4.0
HSQLDB(HyperSQL DataBase)是一个开放源代码的JAVA数据库,其具有标准的SQL语法和JAVA接口,它可以自由使用和分发,非常简洁和快速的
HSQLDB 2.2.9 发布了 Hsqldb是一个开放源代码的JAVA数据库,其具有标准的SQL语法和JAVA接口,它可以自由使用和分发,非常简洁和快速的。具有Server模式,进程内模式(In-Process)和内存模式(Memory-Only)三种。运行...
hsqldb-2.3.3.zip,官方的。
对hsqldb的缓存和表格建立,数据存储机制以及使用eclipse的调试步骤做了详尽的分析,有截图辅助
hsqldb-1.8.0.10.jar