use of org.h2.tools.Shell in project symmetric-ds by JumpMind.
the class DbSqlCommand method executeWithOptions.
@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
BasicDataSource basicDataSource = getDatabasePlatform(false).getDataSource();
String url = basicDataSource.getUrl();
String user = basicDataSource.getUsername();
String password = basicDataSource.getPassword();
String driver = basicDataSource.getDriverClassName();
Shell shell = new Shell();
if (line.hasOption(OPTION_SQL)) {
String sql = line.getOptionValue(OPTION_SQL);
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver, "-sql", sql);
} else {
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver);
}
return true;
}
use of org.h2.tools.Shell in project elastic-core-maven by OrdinaryDude.
the class Helper method executeQuery.
public static String executeQuery(String line) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
out.println(line);
try {
Shell shell = new Shell();
shell.setErr(out);
shell.setOut(out);
shell.runTool(Db.db.getConnection(), "-sql", line);
} catch (SQLException e) {
out.println(e.toString());
}
return new String(baos.toByteArray());
}
use of org.h2.tools.Shell in project elastic-core-maven by OrdinaryDude.
the class DbShellServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
resp.setHeader("Pragma", "no-cache");
resp.setDateHeader("Expires", 0);
if (!API.isAllowed(req.getRemoteHost())) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
String body = null;
if (!API.disableAdminPassword) {
if (API.adminPassword.isEmpty()) {
body = errorNoPasswordIsConfigured;
} else {
try {
API.verifyPassword(req);
if ("true".equals(req.getParameter("showShell"))) {
body = form.replace("{adminPassword}", URLEncoder.encode(req.getParameter("adminPassword"), "UTF-8"));
}
} catch (ParameterException exc) {
String desc = (String) ((JSONObject) JSONValue.parse(JSON.toString(exc.getErrorResponse()))).get("errorDescription");
body = String.format(passwordFormTemplate, "<p style=\"color:red\">" + desc + "</p>");
}
}
}
if (body != null) {
try (PrintStream out = new PrintStream(resp.getOutputStream())) {
out.print(header);
out.print(body);
out.print(barter);
}
return;
}
String line = Convert.nullToEmpty(req.getParameter("line"));
try (PrintStream out = new PrintStream(resp.getOutputStream())) {
out.println("\n> " + line);
try {
Shell shell = new Shell();
shell.setErr(out);
shell.setOut(out);
shell.runTool(Db.db.getConnection(), "-sql", line);
} catch (SQLException e) {
out.println(e.toString());
}
}
}
Aggregations