H2 Datastore: how to execute console from Java app?
I have tested H2 as a server, and now i have it "embedded" in a Eclipse RCP Java App.
Everything works jus开发者_运维百科t fine connecting to the Database engine. Embedded (local) connection jdbc:h2:[file:][]
Now, can i connect to the H2 HTTP Console using the Embedded server?
Virtually, all Eclipse RCP views have browser capability, so the preferred way would be to execute the console inside an RCP view.
Basically i need to set the browser url inside the view: browser.setUrl(url);
But the H2 console must be called specifically with: org.h2.tools.Server.openBrowser(url); This opens the the console into an external browser and does not connect to the embedded browser.
thanks.
You need to start the H2 Console application using:
org.h2.tools.Server.createWebServer().start();
You can also specify the port:
org.h2.tools.Server.createWebServer("-webPort", "10500").start();
After the server is running, connect to it using an Eclipse internal (embedded) browser composite, which seems to be org.eclipse.help.ui.internal.browser.embedded.EmbeddedBrowser. How to open a Eclipse RPC browser has nothing to do with H2.
But the H2 console must be called specifically with: org.h2.tools.Server.openBrowser(url);
No, it doesn't need to be called. This call doesn't start the H2 Console. It starts an external browser (Firefox, Safari,...) and connect to the given URL. If you don't want an external browser, don't call this method.
You can use this code snippet for running H2 database console in browser. This method will open the browser automatically.
public static void main(String[] args) throws SQLException {
Console.main("-browser");
}
精彩评论