HSQLDB 调查

http://hsqldb.org
从上面的网站下载程序包

其中只有LIB/下的hsqldb.jar有用,其他的基本都可以不要了
import org.hsqldb.Server;
import org.hsqldb.ServerConfiguration;
import org.hsqldb.ServerConstants;
import org.hsqldb.lib.FileUtil;
import org.hsqldb.persist.HsqlProperties;


public class DBStart {
	
	public static  void start() {
		String[] args=new String[4];
		//-database.0 file:wxtest -dbname.0 wxtest
		args[0]="-database.0";
		args[1]="file:wxtest";
		args[2]="-dbname.0";
		args[3]="wxtest";
		
		  String propsPath =FileUtil.getDefaultInstance().canonicalOrAbsolutePath("server");
	        HsqlProperties fileProps =ServerConfiguration.getPropertiesFromFile(propsPath);
	        HsqlProperties props = fileProps == null ? new HsqlProperties()
	                                                       : fileProps;
	        HsqlProperties stringProps = null;

	        try {
	            stringProps = HsqlProperties.argArrayToProps(args,
	                    ServerConstants.SC_KEY_PREFIX);
	        } catch (ArrayIndexOutOfBoundsException aioob) {
	            return;
	        }

	        if (stringProps != null) {
	            if (stringProps.getErrorKeys().length != 0) {
	                return;
	            }

	            props.addProperties(stringProps);
	        }
	        ServerConfiguration.translateDefaultDatabaseProperty(props);

	        ServerConfiguration.translateDefaultNoSystemExitProperty(props);

	        // finished setting up properties;
	        Server server = new Server();

	        try {
	            server.setProperties(props);
	        } catch (Exception e) {
	           e.printStackTrace();
	            return;
	        }

	        if (fileProps != null) {
	            System.out.println("Loaded properties from [" + propsPath
	                         + ".properties]");
	        } else {
	        	 System.out.println("Could not load properties from file");
	        	 System.out.println("Using cli/default properties only");
	        }

	        server.start();
	}
	public static void main(String[] args) {
		DBStart.start();
	}

}


将数据库启动,加入到自己的程序中,在类路径下会生成几个数据库文件
之后,启动管理器:java -cp hsqldb.jar org.hsqldb.util.DatabaseManager 就可以对数据库进行操作了
当然,启动数据库也可以 从命令行进行,
如java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:wxtest -dbname.0 wxtest 也是可以的  

简单的操作之后,对HSQLDB的最初印象就是轻便,简单。

随着以后的应用,可能 对其有更深入的理解。

你可能感兴趣的:(UP,HSQLDB)