欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JAVA启动HSQL Server

程序员文章站 2022-05-24 18:23:46
...
HSQL启动Server的命令为
java -cp hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb

为了方便在JAVA程序中能启动它封装了下类org.hsqldb.Server

import org.hsqldb.Server;
import org.hsqldb.ServerConfiguration;
import org.hsqldb.ServerConstants;
import org.hsqldb.lib.FileUtil;
import org.hsqldb.persist.HsqlProperties;

public class HSQLServer extends Server {
public static void start(String[] args) {

String propsPath = FileUtil.canonicalOrAbsolutePath("server");
HsqlProperties fileProps = ServerConfiguration
.getPropertiesFromFile(propsPath);
HsqlProperties props = fileProps == null ? new HsqlProperties()
: fileProps;
HsqlProperties stringProps = HsqlProperties.argArrayToProps(args,
ServerConstants.SC_KEY_PREFIX);

if (stringProps != null) {
if (stringProps.getErrorKeys().length != 0) {
printHelp("server.help");
return;
}
props.addProperties(stringProps);
}
ServerConfiguration.translateDefaultDatabaseProperty(props);

ServerConfiguration.translateDefaultNoSystemExitProperty(props);

Server server = new Server();

server.setProperties(props);

server.start();
}
}


启动方式为;
String[] args=new String[{"-database.0","file:mydb","-dbname.0","xdb"};
HSQLServer.start(args);
相关标签: Java HSQLDB