论坛首页 入门技术论坛

在应用服务器下启动HSQL数据库

浏览 2713 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-04-09  

             说明:

             在应用服务器(tomcat,jboss,weblogic)启动的时候,启动HSQL数据库。

             步骤:

            1。在web.xml下配置监听器

     xml 代码
  1. <listener>  
  2.         <listener-class>  
  3.             com.emap.mds.db.RunHSQLListener   
  4.         listener-class>  
  5.     listener>  

            注意:这个监听器必须配置在spring和其他监听器的前面(在web.xml的顺序)。

        2.编写监听器                 

java 代码
  1. public class RunHSQLListener implements ServletContextListener   
  2. {   
  3.   
  4.     /**  
  5.      * Initialize the root web application context.  
  6.      */  
  7.     public void contextInitialized( ServletContextEvent event)   
  8.     {   
  9.         ServletContext context = event.getServletContext();   
  10.         context.log("开始启动HSQL数据库..");   
  11.         org.hsqldb.Server.main(new String[] { "-database.0",   
  12.                 context.getRealPath("/WEB-INF/db/mds"), "-dbname.0""mds" });   
  13.         context.log("成功启动HSQL数据库");   
  14.     }   
  15.   
  16.     /**  
  17.      * Create the ContextLoader to use. Can be overridden in subclasses.  
  18.      *   
  19.      * @return the new ContextLoader  
  20.      */  
  21.     protected ContextLoader createContextLoader()   
  22.     {   
  23.         return new ContextLoader();   
  24.     }   
  25.   
  26.   
  27.     /**  
  28.      * Close the root web application context.  
  29.      */  
  30.     public void contextDestroyed( ServletContextEvent event)   
  31.     {   
  32.     }   
  33.   
  34. }  

   注意:hsql数据库放在WEB-INF的db文件夹下,cms是数据库名称,别名是cms。

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics