Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

In this page you can find the example usage for java.sql SQLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:fll.web.setup.CreateDB.java

protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {
    String redirect;// w ww . ja va  2s  .  c o  m
    final StringBuilder message = new StringBuilder();
    InitFilter.initDataSource(application);
    final DataSource datasource = ApplicationAttributes.getDataSource(application);
    Connection connection = null;
    try {
        connection = datasource.getConnection();

        // must be first to ensure the form parameters are set
        UploadProcessor.processUpload(request);

        if (null != request.getAttribute("chooseDescription")) {
            final String description = (String) request.getAttribute("description");
            try {
                final URL descriptionURL = new URL(description);
                final Document document = ChallengeParser
                        .parse(new InputStreamReader(descriptionURL.openStream(), Utilities.DEFAULT_CHARSET));

                GenerateDB.generateDB(document, connection);

                application.removeAttribute(ApplicationAttributes.CHALLENGE_DOCUMENT);

                message.append("<p id='success'><i>Successfully initialized database</i></p>");
                redirect = "/admin/createUsername.jsp";

            } catch (final MalformedURLException e) {
                throw new FLLInternalException("Could not parse URL from choosen description: " + description,
                        e);
            }
        } else if (null != request.getAttribute("reinitializeDatabase")) {
            // create a new empty database from an XML descriptor
            final FileItem xmlFileItem = (FileItem) request.getAttribute("xmldocument");

            if (null == xmlFileItem || xmlFileItem.getSize() < 1) {
                message.append("<p class='error'>XML description document not specified</p>");
                redirect = "/setup";
            } else {
                final Document document = ChallengeParser
                        .parse(new InputStreamReader(xmlFileItem.getInputStream(), Utilities.DEFAULT_CHARSET));

                GenerateDB.generateDB(document, connection);

                application.removeAttribute(ApplicationAttributes.CHALLENGE_DOCUMENT);

                message.append("<p id='success'><i>Successfully initialized database</i></p>");
                redirect = "/admin/createUsername.jsp";
            }
        } else if (null != request.getAttribute("createdb")) {
            // import a database from a dump
            final FileItem dumpFileItem = (FileItem) request.getAttribute("dbdump");

            if (null == dumpFileItem || dumpFileItem.getSize() < 1) {
                message.append("<p class='error'>Database dump not specified</p>");
                redirect = "/setup";
            } else {

                ImportDB.loadFromDumpIntoNewDB(new ZipInputStream(dumpFileItem.getInputStream()), connection);

                // remove application variables that depend on the database
                application.removeAttribute(ApplicationAttributes.CHALLENGE_DOCUMENT);

                message.append("<p id='success'><i>Successfully initialized database from dump</i></p>");
                redirect = "/admin/createUsername.jsp";
            }

        } else {
            message.append(
                    "<p class='error'>Unknown form state, expected form fields not seen: " + request + "</p>");
            redirect = "/setup";
        }

    } catch (final FileUploadException fue) {
        message.append("<p class='error'>Error handling the file upload: " + fue.getMessage() + "</p>");
        LOG.error(fue, fue);
        redirect = "/setup";
    } catch (final IOException ioe) {
        message.append("<p class='error'>Error reading challenge descriptor: " + ioe.getMessage() + "</p>");
        LOG.error(ioe, ioe);
        redirect = "/setup";
    } catch (final SQLException sqle) {
        message.append("<p class='error'>Error loading data into the database: " + sqle.getMessage() + "</p>");
        LOG.error(sqle, sqle);
        redirect = "/setup";
    } finally {
        SQLFunctions.close(connection);
    }

    session.setAttribute("message", message.toString());
    response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + redirect));

}

From source file:org.elasticsearch.xpack.qa.sql.jdbc.ErrorsTestCase.java

@Override
public void testSelectInvalidSql() throws Exception {
    try (Connection c = esJdbc()) {
        SQLException e = expectThrows(SQLException.class,
                () -> c.prepareStatement("SELECT * FRO").executeQuery());
        assertEquals("Found 1 problem(s)\nline 1:8: Cannot determine columns for *", e.getMessage());
    }//from  ww  w.j a  va2s . com
}

From source file:gridool.mapred.db.task.DBMapShuffleTaskBase.java

protected final Serializable execute() throws GridException {
    int numShuffleThreads = shuffleThreads();
    this.shuffleExecPool = (numShuffleThreads <= 0) ? new DirectExecutorService()
            : ExecutorFactory.newFixedThreadPool(numShuffleThreads, "Gridool#Shuffle", true);
    this.shuffleSink = new BoundedArrayQueue<OUT_TYPE>(shuffleUnits());

    // execute a query
    final Connection conn;
    try {//ww  w . ja va  2s .  c o m
        conn = jobConf.getConnection(false);
        configureConnection(conn);
    } catch (ClassNotFoundException e) {
        LOG.error(e);
        throw new GridException(e);
    } catch (SQLException e) {
        LOG.error(e);
        throw new GridException(e);
    }
    assert (conn != null);
    final String query = jobConf.getInputQuery();
    final Statement statement;
    final ResultSet results;
    try {
        statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        results = statement.executeQuery(query);
    } catch (SQLException e) {
        try {
            conn.close();
        } catch (SQLException sqle) {// avoid
            LOG.debug(sqle.getMessage());
        }
        LOG.error(e);
        throw new GridException(e);
    }

    try {
        preprocess(conn, results);
    } catch (SQLException e) {
        LOG.error(e);
        throw new GridException(e);
    }

    // Iterate over records
    // process -> shuffle is consequently called
    try {
        while (results.next()) {
            IN_TYPE record = prepareInputRecord();
            readFields(record, results);
            if (!process(record)) {
                break;
            }
        }
    } catch (SQLException e) {
        LOG.error(e);
        throw new GridException(e);
    } finally {
        try {
            statement.close();
        } catch (SQLException e) {
            LOG.debug("failed closing a statement", e);
        }
        try {
            conn.close();
        } catch (SQLException e) {
            LOG.debug("failed closing a connection", e);
        }
    }
    postShuffle();
    return null;
}

From source file:it.gulch.linuxday.android.services.AlarmIntentService.java

private void setupServices() {
    try {/* w  ww  .  jav a 2  s. c  om*/
        eventManager = DatabaseManagerFactory.getEventManager(this);
        bookmarkManager = DatabaseManagerFactory.getBookmarkManager(this);
    } catch (SQLException e) {
        Log.e(TAG, e.getMessage(), e);
    }
}

From source file:mobi.nordpos.catalog.action.ProductCreateActionBean.java

@ValidationMethod
public void validateProductCategoryIdIsAvalaible(ValidationErrors errors) {
    try {/*from   w ww.ja  v  a2s . c  o m*/
        ProductCategoryPersist pcPersist = new ProductCategoryPersist();
        pcPersist.init(getDataBaseConnection());
        ProductCategory category = pcPersist.read(getProduct().getProductCategory().getId());
        if (category != null) {
            getProduct().setProductCategory(category);
        } else {
            errors.add("product.category.id", new SimpleError(getLocalizationKey("error.CatalogNotInclude")));
        }
    } catch (SQLException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
    }
}

From source file:com.taobao.diamond.server.service.HangingModePersistService.java

/**
 * Returns a List(Map) collection.//from   ww  w. j a v  a 2  s.c  o  m
 * 
 * @param cs
 *            object that can create a CallableStatement given a Connection
 * @return resultsList a result object returned by the action, or null
 */
public Object doInCallableStatement(CallableStatement cs) {
    try {
        // cs.setInt(1,1000);
        cs.execute();
    } catch (SQLException e) {
        throw new RuntimeException("doInCallableStatement method error : SQLException " + e.getMessage());
    }
    return null;
}

From source file:Classes.Database.java

/**
 * Login check in database./*from w ww.j  av  a 2  s .  co  m*/
 *
 * @param query     The querry used
 * @param arguments Login Data
 */
public ArrayList<User> LogIn(String query, Object... arguments) {
    try {
        return getDatabase(query, userReturn, arguments);
    } catch (SQLException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
    }
    return new ArrayList<>();
}

From source file:Database.Handler.java

public int aggregateQuery(String sql, String[] para) {
    PreparedStatement ps;// ww w.  j  ava2  s  . c  o  m
    int ret = -1;
    try {
        Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName,
                DbConfig.dbPassword);
        ps = c.prepareStatement(sql);
        for (int i = 0; i < para.length; i++) {
            ps.setString(i + 1, para[i]);
        }
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            ret = rs.getInt(1);
        }
        ps.close();
        c.close();
        return ret;
    } catch (SQLException e) {
        System.out.println("Handler aggregateQuery error:" + e.getMessage());
        return -1;
    }
}

From source file:Database.Handler.java

public String AnyQuery(String sql, String[] para) {
    PreparedStatement ps;// w  w  w.j  ava2s  . co m
    String ret = null;
    try {
        Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName,
                DbConfig.dbPassword);
        ps = c.prepareStatement(sql);
        for (int i = 0; i < para.length; i++) {
            ps.setString(i + 1, para[i]);
        }
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            ret = rs.getString(1);
        }
        ps.close();
        c.close();
        return ret;
    } catch (SQLException e) {
        System.out.println("Handler aggregateQuery error:" + e.getMessage());
        return null;
    }
}

From source file:com.cisco.dvbu.ps.common.util.jdbcapi.JdbcConnector.java

/**
 * Closes established JDBC connection//from w  ww  . ja  va2 s.  c o m
 * 
 * @param conn
 * @throws CompositeException
 */
public void closeJdbcConnection(Connection conn) throws CompositeException {
    if (conn == null) {
        //         throw new CompositeException("Unable to close existing connection - it is already null.");
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to close existing connection - it is already null.");
        }
        return;
    }
    try {
        conn.close();
    } catch (SQLException e) {
        logger.error("Unable to close JDBC connection to CIS:\n", e);
        throw new CompositeException("Unable to close JDBC connection to CIS:\n" + e.getMessage());
    }
}