今天用了一下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();
}
}