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:eionet.cr.dao.readers.NewSourcesReaderWriter.java

@Override
public void readRow(BindingSet bindingSet) throws ResultSetReaderException {

    String sourceUrl = getFirstBindingStringValue(bindingSet);
    if (!StringUtils.isBlank(sourceUrl)) {

        // Replace spaces from url
        sourceUrl = StringUtils.replace(sourceUrl.trim(), " ", "%20");

        sourceCount++;/*from w  w w.jav  a 2 s  .c o  m*/
        try {
            getPreparedStatement().setString(1, sourceUrl);
            getPreparedStatement().setLong(2, Hashes.spoHash(sourceUrl));
            getPreparedStatement().addBatch();
            currentBatchSize++;

            if (currentBatchSize == BATCH_LIMIT) {

                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Inserting " + currentBatchSize + " sources");
                }

                getPreparedStatement().executeBatch();
                getPreparedStatement().clearParameters();
                currentBatchSize = 0;

                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace(sourceCount + " sources inserted so far");
                }
            }

        } catch (SQLException e) {
            throw new ResultSetReaderException(e.getMessage(), e);
        }
    }
}

From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson5b.java

protected AttackResult injectableQuery(String accountName) {
    try {/*from  w  w w. j  a  v  a 2  s .  c om*/
        Connection connection = DatabaseUtilities.getConnection(getWebSession());
        String query = "SELECT * FROM user_data WHERE userid = " + accountName;

        try {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet results = statement.executeQuery(query);

            if ((results != null) && (results.first() == true)) {
                ResultSetMetaData resultsMetaData = results.getMetaData();
                StringBuffer output = new StringBuffer();

                output.append(writeTable(results, resultsMetaData));
                results.last();

                // If they get back more than one user they succeeded
                if (results.getRow() >= 6) {
                    return trackProgress(AttackResult.success("You have succeed: " + output.toString()));
                } else {
                    return trackProgress(AttackResult.failed("You are close, try again. " + output.toString()));
                }

            } else {
                return trackProgress(AttackResult.failed("No Results Matched. Try Again. "));

                //                    output.append(getLabelManager().get("NoResultsMatched"));
            }
        } catch (SQLException sqle) {

            return trackProgress(AttackResult.failed(sqle.getMessage()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return trackProgress(
                AttackResult.failed("ErrorGenerating" + this.getClass().getName() + " : " + e.getMessage()));
    }
}

From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson6a.java

protected AttackResult injectableQuery(String accountName) {
    try {/*from  w w  w. ja  v a  2s . c o  m*/
        Connection connection = DatabaseUtilities.getConnection(getWebSession());
        String query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'";

        try {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet results = statement.executeQuery(query);

            if ((results != null) && (results.first() == true)) {
                ResultSetMetaData resultsMetaData = results.getMetaData();
                StringBuffer output = new StringBuffer();

                output.append(writeTable(results, resultsMetaData));
                results.last();

                // If they get back more than one user they succeeded
                if (results.getRow() >= 6) {
                    return trackProgress(AttackResult.success("You have succeed: " + output.toString()));
                } else {
                    return trackProgress(AttackResult.failed("You are close, try again. " + output.toString()));
                }

            } else {
                return trackProgress(AttackResult.failed("No Results Matched. Try Again. "));

            }
        } catch (SQLException sqle) {

            return trackProgress(AttackResult.failed(sqle.getMessage()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return trackProgress(
                AttackResult.failed("ErrorGenerating" + this.getClass().getName() + " : " + e.getMessage()));
    }
}

From source file:gov.nih.nci.cacisweb.dao.virtuoso.VirtuosoCDWUserPermissionDAO.java

@Override
public boolean isUserExists(CdwUserModel cdwUserModel) throws DAOException {
    log.debug("isUserExists(CDWUserModel cdwUserModel) - start");
    boolean isUserExists = false;
    StringBuffer query = new StringBuffer();
    query.append("SELECT U_ID FROM DB.DBA.SYS_USERS WHERE U_NAME=?");
    try {/*from   w w  w  . j  a  v  a2 s  . co m*/
        pstmt = new LoggableStatement(cacisConnection, query.toString());
        pstmt.setString(1, cdwUserModel.getUsername());
        log.info("SQL in isUserExists(CDWUserModel cdwUserModel): " + pstmt.toString());
        rs = pstmt.executeQuery();
        if (rs.next()) {
            isUserExists = true;
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
        throw new DAOException(sqle.getMessage());
    }
    log.debug("isUserExists(CDWUserModel cdwUserModel) - end");
    return isUserExists;
}

From source file:fll.web.report.finalist.StoreFinalistSchedule.java

@Override
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {

    final StringBuilder message = new StringBuilder();

    Connection connection = null;
    try {/*from  w w  w.  j  a v a2  s . c o m*/
        final DataSource datasource = ApplicationAttributes.getDataSource(application);
        connection = datasource.getConnection();

        final int tournament = Queries.getCurrentTournament(connection);

        // get parameters
        final String schedDataStr = request.getParameter("sched_data");
        if (null == schedDataStr || "".equals(schedDataStr)) {
            throw new FLLRuntimeException("Parameter 'sched_data' cannot be null");
        }

        final String categoryDataStr = request.getParameter("category_data");
        if (null == categoryDataStr || "".equals(categoryDataStr)) {
            throw new FLLRuntimeException("Parameter 'category_data' cannot be null");
        }

        final String division = request.getParameter("division_data");
        if (null == division || "".equals(division)) {
            throw new FLLRuntimeException("Parameter 'division_data' cannot be null");
        }

        final String nomineesStr = request.getParameter("non-numeric-nominees_data");
        if (null == nomineesStr || "".equals(nomineesStr)) {
            throw new FLLRuntimeException("Parameter 'non-numeric-nominees_data' cannot be null");
        }

        // decode JSON
        final ObjectMapper jsonMapper = new ObjectMapper();

        final Collection<FinalistDBRow> rows = jsonMapper.readValue(schedDataStr,
                FinalistScheduleTypeInformation.INSTANCE);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Sched Data has " + rows.size() + " rows");
            for (final FinalistDBRow row : rows) {
                LOGGER.trace("row category: " + row.getCategoryName() + " time: " + row.getTime() + " team: "
                        + row.getTeamNumber());
            }
        }

        final Collection<FinalistCategory> categories = jsonMapper.readValue(categoryDataStr,
                FinalistCategoriesTypeInformation.INSTANCE);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Category Data has " + rows.size() + " rows");
        }

        final FinalistSchedule schedule = new FinalistSchedule(tournament, division, categories, rows);
        schedule.store(connection);

        final Collection<NonNumericNominees> nominees = jsonMapper.readValue(nomineesStr,
                NonNumericNomineesTypeInformation.INSTANCE);
        for (final NonNumericNominees nominee : nominees) {
            nominee.store(connection, tournament);
        }

        message.append("<p id='success'>Finalist schedule saved to the database</p>");

    } catch (final SQLException e) {
        message.append("<p class='error'>Error saving finalist schedule into the database: " + e.getMessage()
                + "</p>");
        LOGGER.error(e, e);
        throw new RuntimeException("Error saving subjective data into the database", e);
    }

    session.setAttribute("message", message.toString());
    response.sendRedirect(response.encodeRedirectURL("schedule-saved.jsp"));

}

From source file:pl.edu.agh.iosr.lsf.RootController.java

@RequestMapping(value = "keyword/gen", method = RequestMethod.GET)
public String genKeywords(@RequestParam(value = "n") int n) {

    int c = 0;/*from   w  w w  .ja va  2 s  .c  om*/
    try {
        for (String[] s : dh.listKeywords()) {
            dh.deleteKeyword(s[1]);
        }

        for (String s : DatabaseHelper.loadWords().subList(0, n)) {
            dh.insertKeyword(s, "positive");
            c++;
        }
    } catch (SQLException e) {
        return e.getMessage();
    }

    return "OK " + c;
}

From source file:co.nubetech.apache.hadoop.DBRecordReader.java

/** {@inheritDoc} */
public void close() throws IOException {
    try {/*from  w  w  w.  j a v  a  2  s.  com*/
        if (null != results) {
            results.close();
        }
        if (null != statement) {
            statement.close();
        }
        if (null != connection) {
            connection.commit();
            connection.close();
        }
    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.nextep.designer.data.ui.editors.DataSetComparisonEditor.java

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    if (input instanceof TypedEditorInput) {
        try {/*from www.j av a 2  s  .  c o m*/
            connection = DbgmPlugin.getService(IStorageService.class).getLocalConnection();
        } catch (SQLException e) {
            throw new ErrorException(DataUiMessages.getString("editor.dataset.comparison.localConnectionFailed") //$NON-NLS-1$
                    + e.getMessage(), e);
        }
        setInput(input);
        setSite(site);
    }
}

From source file:org.openiot.gsn.http.rest.PushRemoteWrapper.java

public boolean manualDataInsertion(String Xstream4Rest) {
    logger.debug(new StringBuilder().append("Received Stream Element at the push wrapper."));
    try {//  ww  w.j  a v a 2 s.co  m

        StreamElement4Rest se = (StreamElement4Rest) XSTREAM.fromXML(Xstream4Rest);
        StreamElement streamElement = se.toStreamElement();

        // If the stream element is out of order, we accept the stream element and wait for the next (update the last received time and return true)
        if (isOutOfOrder(streamElement)) {
            lastReceivedTimestamp = streamElement.getTimeStamp();
            return true;
        }
        // Otherwise, we first try to insert the stream element.
        // If the stream element was inserted succesfully, we wait for the next,
        // otherwise, we return false.
        boolean status = postStreamElement(streamElement);
        if (status)
            lastReceivedTimestamp = streamElement.getTimeStamp();
        return status;
    } catch (SQLException e) {
        logger.warn(e.getMessage(), e);
        return false;
    } catch (XStreamException e) {
        logger.warn(e.getMessage(), e);
        return false;
    }
}

From source file:com.tascape.qa.th.db.H2Handler.java

@Override
public void init() throws Exception {
    File dir = new File(this.dbPath);
    if (dir.exists()) {
        FileUtils.cleanDirectory(dir);/*from w w  w .  j a  v  a2 s . co m*/
    }
    this.connPool = JdbcConnectionPool.create("jdbc:h2:" + this.dbPath + SYS_CONFIG.getExecId(), "sa", "sa");
    connPool.setMaxConnections(10);
    try (Connection conn = this.getConnection()) {
        try {
            conn.prepareStatement("SELECT * FROM test_result WHERE 0;").executeQuery();
        } catch (SQLException ex) {
            LOG.warn("{}", ex.getMessage());
            this.initSchema();
        }
    }
}