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:pl.edu.agh.iosr.lsf.RootController.java

@RequestMapping(value = "user/monitored", method = RequestMethod.POST)
public String monitorUser(@RequestParam(value = "name") String tag) throws SQLException {
    try {/* w  ww  .  ja  v a 2 s .  c  o m*/
        dh.monitorUser(tag);
        return "OK";
    } catch (SQLException e) {
        return e.getMessage();
    }
}

From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCRatingsDao.java

/**
 *
 * @param userid/*from  w w w .j ava2s . c o m*/
 * @param terms
 * @throws RatingsDaoException
 */
@Override
public void giveRating(long userid, Map<String, Double> terms) throws RatingsDaoException {
    try {
        logger.debug("updating ratings in batch");
        for (String term : terms.keySet()) {
            double rating = terms.get(term);
            insertUpdateRatingStatement.setLong(1, userid);
            insertUpdateRatingStatement.setString(2, term);
            insertUpdateRatingStatement.setDouble(3, rating);
            insertUpdateRatingStatement.setDouble(4, rating);
            insertUpdateRatingStatement.addBatch();
        }

        int[] result = insertUpdateRatingStatement.executeBatch();
        logger.debug("length return value insert/update: " + result.length);
    } catch (SQLException ex) {
        logger.error("Error updating rating", ex);
        throw new RatingsDaoException("Error updating rating: " + ex.getMessage(), ex);
    }
}

From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java

/**
 * Save subscription charge rate nb.//from   w  w w.  java  2  s .  c om
 *
 * @param appId the app id
 * @param apiId the api id
 * @throws Exception the exception
 */
public void saveSubscriptionChargeRateNB(String appId, String apiId) throws Exception {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    try {
        String apiName = apiManagerDAO.getApiNameById(Integer.valueOf(apiId));
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        String sql = "SELECT operation_id,default_rate FROM " + ReportingTable.API_OPERATION_TYPES
                + "  WHERE api=?";
        ps = conn.prepareStatement(sql);
        ps.setString(1, apiName);
        log.debug("SQL (PS) ---> " + ps.toString());
        rs = ps.executeQuery();

        while (rs.next()) {
            Integer opId = Integer.parseInt(rs.getString("operation_id"));
            String defaultRate = rs.getString("default_rate");

            String query = "INSERT INTO  " + ReportingTable.SUBSCRIPTION_RATES_NB
                    + " (`application_id`, `api_id`, `rate_id_nb`, `operation_id`) VALUES (?, ?, ?, ?)";
            ps = conn.prepareStatement(query);
            ps.setInt(1, Integer.parseInt(appId));
            ps.setInt(2, Integer.parseInt(apiId));
            ps.setString(3, defaultRate);
            ps.setInt(4, opId);
            ps.executeUpdate();
        }

    } catch (SQLException e) {
        handleException("Error in Creating subscription charge rate : " + e.getMessage(), e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, rs);
    }
}

From source file:edu.pitt.resumecore.Medication.java

public Medication(String medID) {
    db = new MySqlDbUtilities();

    String sql = "SELECT * FROM emr.medications a, emr.medicationcategories b" + " WHERE medID = '" + medID
            + "' AND a.categoryId = b.categoryId;";

    try {/*from ww w. j a v a  2s.  c o m*/
        ResultSet rs = db.getResultSet(sql);
        if (rs.next()) {
            this.medID = rs.getString("medID");
            this.categoryID = rs.getString("categoryID");
            this.medicationName = rs.getString("medication");
            this.categoryName = rs.getString("categoryName");
        }

    } catch (SQLException ex) {
        ErrorLogger.log("An error had occured in Medication(String medID) constructor of Medication class"
                + ex.getMessage());
        ErrorLogger.log(sql);
    } finally {
        db.closeDbConnection();
    }
}

From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCRatingsDao.java

/**
 *
 * @param userid//www.  j  a va2  s  .co  m
 * @return
 * @throws RatingsDaoException
 */
@Override
public Map<String, Double> getRatings(long userid) throws RatingsDaoException {
    try {
        logger.debug("get rating for user: " + userid);
        selectStatement.setLong(1, userid);
        Map<String, Double> ratings;
        try (ResultSet results = selectStatement.executeQuery()) {
            ratings = new HashMap<>();
            while (results.next()) {
                ratings.put(results.getString(1), results.getDouble(2));
            }
        }
        return ratings;
    } catch (SQLException ex) {
        logger.error("Error fetching ratings", ex);
        throw new RatingsDaoException("Error fetching ratings: " + ex.getMessage(), ex);
    }

}

From source file:com.l2jfree.gameserver.instancemanager.CastleManager.java

@Override
public void loadInstances() {
    Connection con = null;//from   w ww.  j  a v a2 s.c o m
    try {
        PreparedStatement statement;
        ResultSet rs;

        con = L2DatabaseFactory.getInstance().getConnection(con);

        statement = con.prepareStatement("SELECT id FROM castle ORDER BY id");
        rs = statement.executeQuery();

        while (rs.next()) {
            int id = rs.getInt("id");
            getCastles().put(id, new Castle(id));
        }

        statement.close();

        _log.info("Loaded: " + getCastles().size() + " castles");
    } catch (SQLException e) {
        _log.warn("Exception: loadCastleData(): " + e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java

/**
 * Save subscription charge rate.//from  www.j  a v  a 2  s.  c  o m
 *
 * @param appId the app id
 * @param apiId the api id
 * @param opName the op name
 * @throws Exception the exception
 */
public void saveSubscriptionChargeRate(String appId, String apiId, String opName) throws Exception {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    try {
        String apiName = apiManagerDAO.getApiNameById(Integer.valueOf(apiId));
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        String sql = "SELECT operation_id,default_rate FROM " + ReportingTable.API_OPERATION_TYPES
                + " WHERE api=?";
        ps = conn.prepareStatement(sql);
        ps.setString(1, apiName);
        log.debug("SQL (PS) ---> " + ps.toString());
        rs = ps.executeQuery();

        while (rs.next()) {
            Integer opId = Integer.parseInt(rs.getString("operation_id"));
            String defaultRate = rs.getString("default_rate");

            String query = "INSERT INTO " + ReportingTable.SUBSCRIPTION_RATES
                    + " (`application_id`, `api_id`, `operator_name`, `rate_id_sb`, `operation_id`) VALUES (?, ?, ?, ?, ?)";
            ps = conn.prepareStatement(query);
            ps.setInt(1, Integer.parseInt(appId));
            ps.setInt(2, Integer.parseInt(apiId));
            ps.setString(3, opName);
            ps.setString(4, defaultRate);
            ps.setInt(5, opId);
            ps.executeUpdate();
        }

    } catch (SQLException e) {
        handleException("Error in Creating subscription charge rate : " + e.getMessage(), e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, rs);
    }
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * With this method the devices can subscribe. Names as ID have to be
 * defined. The devices of the first component are saved in the table
 * "InputDevices". The devices of the second component are saved in the
 * table "OutputDevices".//from w w w . j  a  va  2  s . com
 * 
 * @param component
 *            1 or 2
 * @param classes
 *            name of the class the device belong to
 * @param name
 *            name to be chosen
 */
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Path("/anmelden/{component}/{classes}/{name}")
public static synchronized String subscribe(@PathParam("component") int component,
        @PathParam("classes") String classes, @PathParam("name") String name) {
    String ok = "ok";
    createDBConnection();
    name.replaceAll("\"", "\\\"");
    try {
        if (component == 1) {
            PreparedStatement st = conn.prepareStatement("select class from \"Classes\" where class=?");
            st.setString(1, classes);
            ResultSet result = st.executeQuery();
            if (result.next()) {
                Statement statement = conn.createStatement();
                statement.execute("insert into \"" + classes + "\"(nameinput) values ('" + name + "');");
                st = conn.prepareStatement("insert into \"InputDevices\"(class,name) values (?,?);");
                st.setString(1, classes);
                st.setString(2, name);
                st.execute();

            } else {
                ok = "class not found";
            }

        }

        if (component == 2) {
            PreparedStatement st = conn.prepareStatement("select class from \"Classes\"where class=?");
            st.setString(1, classes);
            ResultSet result = st.executeQuery();
            if (result.next()) {
                deviceActive.put(classes + "," + name, true);
                createDBConnection();
                st = conn.prepareStatement(
                        "insert into \"OutputDevices\"(class,topic,enabled) values (?,?,'t');");
                st.setString(1, classes);
                st.setString(2, name);
                st.execute();

            } else {
                ok = "class not found";
            }
        }

    } catch (SQLException e) {

        String message = e.getMessage();
        if (!message.contains("doppelter Schlsselwert")) {
            logger.error("SQL Exception", e);
        }

    }
    closeDBConnection();
    return ok;
}

From source file:com.flexive.core.stream.BinaryUploadProtocol.java

/**
 * {@inheritDoc}// w  w  w . ja v a 2  s.c  om
 */
@Override
public synchronized boolean receiveStream(ByteBuffer buffer) throws IOException {
    if (!buffer.hasRemaining()) {
        //this can only happen on remote clients
        if (LOG.isDebugEnabled())
            LOG.debug("aborting (empty)");
        return false;
    }
    if (!rcvStarted) {
        rcvStarted = true;
        if (LOG.isDebugEnabled())
            LOG.debug("(internal serverside) receive start");
        try {
            pout = getContentStorage().receiveTransitBinary(division, handle, mimeType, expectedLength,
                    timeToLive);
        } catch (SQLException e) {
            LOG.error("SQL Error trying to receive binary stream: " + e.getMessage(), e);
        } catch (FxNotFoundException e) {
            LOG.error("Failed to lookup content storage for division #" + division + ": "
                    + e.getLocalizedMessage());
        }
    }
    if (LOG.isDebugEnabled() && count + buffer.remaining() > expectedLength) {
        LOG.debug("poss. overflow: pos=" + buffer.position() + " lim=" + buffer.limit() + " cap="
                + buffer.capacity());
        LOG.debug("Curr count: " + count + " count+rem="
                + (count + buffer.remaining() + " delta:" + ((count + buffer.remaining()) - expectedLength)));
    }
    count += buffer.remaining();
    pout.write(buffer.array(), buffer.position(), buffer.remaining());
    buffer.clear();
    if (expectedLength > 0 && count >= expectedLength) {
        if (LOG.isDebugEnabled())
            LOG.debug("aborting");
        return false;
    }
    return true;
}

From source file:com.gs.obevo.db.impl.platforms.db2.Db2SqlExecutorTest.java

@Test
public void testFindTableNameFromSQLException668() {
    SQLException diagnosable = mock(SQLException.class);
    // Note: We will be using SqlErrmc code alone inside the findTableFromSQLException method. Hence we are mocking
    // only the getSqlErrmc method
    when(diagnosable.getMessage())
            .thenReturn("DB2 SQL error: SQLCODE: -668, SQLSTATE: 57016, SQLERRMC: 7;MY_SCHEMA.MYTAB2_");
    assertEquals(Tuples.pair(new PhysicalSchema("MY_SCHEMA"), "MYTAB2_"),
            this.executor.findTableNameFromException(diagnosable, -668));

    verify(diagnosable, times(1)).getMessage();
}