サーブレットコンテキストリスナーでh2データベースを起動します。
public void contextInitialized(ServletContextEvent sce) {
org.h2.Driver.load();
String apprealPath = sce.getServletContext().getRealPath("\\");
String h2Url = "jdbc:h2:file:" + apprealPath + "DB\\cdb;AUTO_SERVER=true";
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
logger.debug("h2 url : " + h2Url);
try {
conn = DriverManager.getConnection(h2Url, "sa", "sa");
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("h2 database started in embedded mode");
sce.getServletContext().setAttribute("connection", conn);
}
次に、dbvisualizerを使用して、次のURLを使用してh2に接続しようとします。
jdbc:h2:tcp://localhost/~/cdb
ただし、次のエラーメッセージが表示されます。
An error occurred while establishing the connection:
Type: org.h2.jdbc.JdbcSQLException Error Code: 90067 SQL State: 90067
Message:
Connection is broken: "Connection refused: connect" [90067-148]
localhostを「172.17.33.181:58524」(cdb.lock.dbで見つけました)に置き換えようとしましたが、ユーザー「sa」のパスワード「sa」で再接続すると、サーバーの応答が次のように変更されました:間違ったユーザー名またはパスワード!