本文整理汇总了Java中org.h2.tools.Server.start方法的典型用法代码示例。如果您正苦于以下问题:Java Server.start方法的具体用法?Java Server.start怎么用?Java Server.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.Server
的用法示例。
在下文中一共展示了Server.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLowerCaseIdentifiers
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testLowerCaseIdentifiers() throws SQLException {
if (!getPgJdbcDriver()) {
return;
}
deleteDb("test");
Connection conn = getConnection(
"test;DATABASE_TO_UPPER=false", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar(255))");
Server server = Server.createPgServer(
"-baseDir", getBaseDir(), "-pgPort", "5535", "-pgDaemon");
server.start();
try {
Connection conn2;
conn2 = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
stat = conn2.createStatement();
stat.execute("select * from test");
conn2.close();
} finally {
server.stop();
}
conn.close();
deleteDb("test");
}
示例2: testPgAdapter
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testPgAdapter() throws SQLException {
deleteDb("test");
Server server = Server.createPgServer(
"-baseDir", getBaseDir(), "-pgPort", "5535", "-pgDaemon");
assertEquals(5535, server.getPort());
assertEquals("Not started", server.getStatus());
server.start();
assertStartsWith(server.getStatus(), "PG server running at pg://");
try {
if (getPgJdbcDriver()) {
testPgClient();
}
} finally {
server.stop();
}
}
示例3: testKeyAlias
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testKeyAlias() throws SQLException {
if (!getPgJdbcDriver()) {
return;
}
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "test", "mem:test");
server.start();
try {
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
Statement stat = conn.createStatement();
// confirm that we've got the in memory implementation
// by creating a table and checking flags
stat.execute("create table test(id int primary key, name varchar)");
ResultSet rs = stat.executeQuery(
"select storage_type from information_schema.tables " +
"where table_name = 'TEST'");
assertTrue(rs.next());
assertEquals("MEMORY", rs.getString(1));
conn.close();
} finally {
server.stop();
}
}
示例4: testOldClientNewServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testOldClientNewServer() throws Exception {
Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001");
server.start();
assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect(
"jdbc:h2:tcp://localhost:9001/mem:test", null);
server.stop();
Class<?> serverClass = cl.loadClass("org.h2.tools.Server");
Method m;
m = serverClass.getMethod("createTcpServer", String[].class);
Object serverOld = m.invoke(null, new Object[] { new String[] {
"-tcpPort", "9001" } });
m = serverOld.getClass().getMethod("start");
m.invoke(serverOld);
Connection conn;
conn = org.h2.Driver.load().connect("jdbc:h2:mem:", null);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("call 1");
rs.next();
assertEquals(1, rs.getInt(1));
conn.close();
m = serverOld.getClass().getMethod("stop");
m.invoke(serverOld);
}
示例5: testAlreadyRunning
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testAlreadyRunning() throws Exception {
Server server = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
server.start();
assertTrue(server.getStatus().contains("server running"));
Server server2 = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
assertEquals("Not started", server2.getStatus());
try {
server2.start();
fail();
} catch (Exception e) {
assertTrue(e.toString().contains("port may be in use"));
assertTrue(server2.getStatus().contains(
"could not be started"));
}
server.stop();
}
示例6: main
import org.h2.tools.Server; //导入方法依赖的package包/类
public static void main(String[] args)
{
System.setProperty("H2_HOME","d:/tmp/h2db/");
String[] params = new String[]{"-tcpPort","8081","-tcp","-tcpAllowOthers","-baseDir","d:/tmp/h2"};
Server h2serve =new Server();
try
{
Server s = Server.createTcpServer(params);
s.start();
System.out.println(s);
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:8081/gemlite_manager2;USER=gemlite");
System.out.println(conn);
conn.close();
Thread.sleep(Long.MAX_VALUE);
}
catch (SQLException | InterruptedException e)
{
e.printStackTrace();
}
}
示例7: runTool
import org.h2.tools.Server; //导入方法依赖的package包/类
@Override
public void runTool(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage();
return;
} else if (arg.startsWith("-ftp")) {
if ("-ftpPort".equals(arg)) {
i++;
} else if ("-ftpDir".equals(arg)) {
i++;
} else if ("-ftpRead".equals(arg)) {
i++;
} else if ("-ftpWrite".equals(arg)) {
i++;
} else if ("-ftpWritePassword".equals(arg)) {
i++;
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
showUsageAndThrowUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
} else {
showUsageAndThrowUnsupportedOption(arg);
}
}
Server server = new Server(this, args);
server.start();
out.println(server.getStatus());
}
示例8: testServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testServer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties",
"null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
client.setAcceptLanguage("de-de,de;q=0.5");
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
assertEquals("text/html", client.getContentType());
assertContains(result, "Einstellung");
client.get(url, "favicon.ico");
assertEquals("image/x-icon", client.getContentType());
client.get(url, "ico_ok.gif");
assertEquals("image/gif", client.getContentType());
client.get(url, "tree.js");
assertEquals("text/javascript", client.getContentType());
client.get(url, "stylesheet.css");
assertEquals("text/css", client.getContentType());
client.get(url, "admin.do");
try {
client.get(url, "adminShutdown.do");
} catch (IOException e) {
// expected
Thread.sleep(1000);
}
} finally {
server.shutdown();
}
// it should be stopped now
server = Server.createTcpServer("-tcpPort", "9101");
server.start();
server.stop();
}
示例9: testReadOnlyInZip
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testReadOnlyInZip() throws SQLException {
if (config.cipher != null) {
return;
}
deleteDb("readonlyInZip");
String dir = getBaseDir();
Connection conn = getConnection("readonlyInZip");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS " +
"SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close();
Backup.execute(dir + "/readonly.zip", dir, "readonlyInZip", true);
conn = getConnection(
"jdbc:h2:zip:"+dir+"/readonly.zip!/readonlyInZip", getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir);
server.start();
try {
conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonlyInZip",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
FilePathZip2.register();
conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonlyInZip",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
} finally {
server.stop();
}
deleteDb("readonlyInZip");
}
示例10: main
import org.h2.tools.Server; //导入方法依赖的package包/类
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
// start the server, allows to access the database remotely
Server server = Server.createTcpServer("-tcpPort", "9081");
server.start();
System.out.println(
"You can access the database remotely now, using the URL:");
System.out.println(
"jdbc:h2:tcp://localhost:9081/~/test (user: sa, password: sa)");
// now use the database in your application in embedded mode
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:h2:~/test", "sa", "sa");
// some simple 'business usage'
Statement stat = conn.createStatement();
stat.execute("DROP TABLE TIMER IF EXISTS");
stat.execute("CREATE TABLE TIMER(ID INT PRIMARY KEY, TIME VARCHAR)");
System.out.println("Execute this a few times: " +
"SELECT TIME FROM TIMER");
System.out.println("To stop this application " +
"(and the server), run: DROP TABLE TIMER");
try {
while (true) {
// runs forever, except if you drop the table remotely
stat.execute("MERGE INTO TIMER VALUES(1, NOW())");
Thread.sleep(1000);
}
} catch (SQLException e) {
System.out.println("Error: " + e.toString());
}
conn.close();
// stop the server
server.stop();
}
示例11: InvoicePortImpl
import org.h2.tools.Server; //导入方法依赖的package包/类
public InvoicePortImpl() throws Exception {
// Start the H2 database in MIXED mode - this means we can allow
// access via the web console (HTTP)
// and use a (faster) embedded connection for the service's
// backend.
// See http://www.h2database.com/html/features.html#connection_modes
Server server = Server.createWebServer("-web", "-webAllowOthers",
"-webPort", "9081");
server.start();
// Alternatively use a TCP server connection to allow connections from
// other JDBC clients
// e.g. Squirrel - connection string will then be like
//jdbc:h2:tcp://localhost:9082/./invoicev3-testdb
//Server server2 = Server.createTcpServer("-tcpPort", "9082");
//server2.start();
System.out
.println("You can access the database remotely now, using the URL:");
System.out.println("http://localhost:9081/" + DB_FILE_LOCATION
+ " (user: '', password: '')");
Class.forName("org.h2.Driver");
dbConnection = DriverManager.getConnection("jdbc:h2:"
+ DB_FILE_LOCATION);
Statement sqlStatment = dbConnection.createStatement();
sqlStatment
.execute("create table if not exists invoices(id identity primary key, invoiceNo varchar(255),"
+ " customerRef varchar(255), amount varchar(255), dueDate date, lastUpated timestamp default NOW())");
sqlStatment.close();
System.out.println("invoices table created...");
}
示例12: main
import org.h2.tools.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {
String[] arg = { "-tcp", "-tcpAllowOthers" };
Server server = Server.createTcpServer(arg);
server.start();
System.out.println("JVM running for");
}
示例13: main
import org.h2.tools.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
killProcess();
}
}));
String[] arg = { "-tcp", "-tcpAllowOthers" };
Server server = Server.createTcpServer(arg);
server.start();
init();
}
示例14: main
import org.h2.tools.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {
String[] arg = { "-tcp", "-tcpAllowOthers" };
Server server = Server.createTcpServer(arg);
server.start();
new MainFrame().setVisible(true);
}
示例15: testCancelQuery
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testCancelQuery() throws Exception {
if (!getPgJdbcDriver()) {
return;
}
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "test", "mem:test");
server.start();
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
final Statement stat = conn.createStatement();
stat.execute("create alias sleep for \"java.lang.Thread.sleep\"");
// create a table with 200 rows (cancel interval is 127)
stat.execute("create table test(id int)");
for (int i = 0; i < 200; i++) {
stat.execute("insert into test (id) values (rand())");
}
Future<Boolean> future = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws SQLException {
return stat.execute("select id, sleep(5) from test");
}
});
// give it a little time to start and then cancel it
Thread.sleep(100);
stat.cancel();
try {
future.get();
throw new IllegalStateException();
} catch (ExecutionException e) {
assertStartsWith(e.getCause().getMessage(),
"ERROR: canceling statement due to user request");
} finally {
conn.close();
}
} finally {
server.stop();
executor.shutdown();
}
deleteDb("test");
}