Search in sources :

Example 1 with Shell

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;
}
Also used : Shell(org.h2.tools.Shell) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 2 with Shell

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());
}
Also used : PrintStream(java.io.PrintStream) Shell(org.h2.tools.Shell) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with Shell

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());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Shell(org.h2.tools.Shell) JSONObject(org.json.simple.JSONObject) SQLException(java.sql.SQLException)

Aggregations

Shell (org.h2.tools.Shell)3 PrintStream (java.io.PrintStream)2 SQLException (java.sql.SQLException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 JSONObject (org.json.simple.JSONObject)1