Hsqldb体验

今天用了一下Hsqldb,感觉很精致。特别是Standalone Mode 就是单机板的数据库,集成到应用中很方便。

对比一下Hsqldb运行的方式:

Memory-Only Databases 不做持久话,无密码,不允许远程访问。
Hsqldb Server 做持久话 ,可以设置密码(设置密码修改test.script文件的user表中的值即可),允许远程访问。
In-Process (Standalone) Mode  做持久话 ,可以设置密码(设置密码修改test.script文件的user表中的值即可),不允许远程访问,独占访问。

public class HspldbConnection
{
    /**
     * 运行前要启动服务器,Memory-Only
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public static void testMemoryOnly() throws SQLException, ClassNotFoundException{
        Class.forName("org.hsqldb.jdbcDriver");
        Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:.", "sa", "");
        c.close();
    }

   /**
    * 运行前要启动服务器,Hsqldb Server
    * @throws SQLException
    * @throws ClassNotFoundException
    */
    public static void testServer() throws SQLException, ClassNotFoundException{
            Class.forName("org.hsqldb.jdbcDriver" );
            Connection c = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/","sa","");
            c.close();
    }

    /**
     * 运行前不用要启动服务器,获得数据库链接及启动了服务器。
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public static void testStandalone() throws SQLException, ClassNotFoundException{
        Class.forName("org.hsqldb.jdbcDriver" );
        Connection c = DriverManager.getConnection("jdbc:hsqldb:file:data/test","sa","");
        c.close();
    }
    public static void main(String args[]) throws SQLException, ClassNotFoundException{
        testMemoryOnly();
        testServer();
        testStandalone();
    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值