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:uk.org.rbc1b.roms.controller.report.ReportsController.java

/**
 * Run a fixed report, returning the data in html format.
 * @param reportId report id/*from  w w w  .j a v  a  2  s . co  m*/
 * @param model model
 * @return view name
 */
@RequestMapping(value = "fixed/{reportId}/html", method = RequestMethod.GET)
@PreAuthorize("hasPermission('REPORT', 'READ')")
public String runHtmlReport(@PathVariable Integer reportId, ModelMap model) {

    FixedReport fixedReport = reportDao.findFixedReport(reportId);
    if (fixedReport == null) {
        throw new ResourceNotFoundException("No fixed report #" + reportId);
    }
    model.addAttribute("report", createFixedReportModel(fixedReport));
    try {
        ReportResults reportResults = extractResults(fixedReport.getQuery());
        model.addAttribute("columnNames", reportResults.columnNames);
        model.addAttribute("resultRows", reportResults.resultRows);
    } catch (SQLException e) {
        throw new IllegalStateException("Failed to extract report data. Message: [" + e.getMessage() + "]", e);
    }

    return "reports/fixed/show-html";
}

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

public boolean manualDataInsertion(StreamElement se) {
    try {/*w ww  . j a  v  a  2s.c o m*/
        // 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(se)) {
            lastReceivedTimestamp = se.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(se);
        if (status)
            lastReceivedTimestamp = se.getTimeStamp();
        return status;
    } catch (SQLException e) {
        logger.warn(e.getMessage(), e);
        return false;
    }
}

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

@Override
public int deleteUser(CdwUserModel cdwUserModel) throws DAOException {
    log.debug("deleteUser(CdwUserModel cdwUserModel) - start");
    StringBuffer query = new StringBuffer();
    query.append(/*w  w  w.  j a v a  2 s.c  o m*/
            "DELETE FROM RDF_GRAPH_USER WHERE RGU_USER_ID = (SELECT U_ID FROM SYS_USERS WHERE U_NAME = ?)");
    try {
        pstmt = new LoggableStatement(cacisConnection, query.toString());
        pstmt.setString(1, cdwUserModel.getUsername());
        log.info(
                "DELETE FROM RDF_GRAPH_USER SQL in deleteUser(CDWUserModel cdwUserModel): " + pstmt.toString());
        int rowsDeleted = pstmt.executeUpdate();
        log.info("No. of permissions deleted: " + rowsDeleted);

        query = new StringBuffer();
        query.append("DELETE from SYS_USERS where U_NAME = ?");
        pstmt = new LoggableStatement(cacisConnection, query.toString());
        pstmt.setString(1, cdwUserModel.getUsername());
        log.info("DELETE from SYS_USERS SQL in deleteUser(CDWUserModel cdwUserModel): " + pstmt.toString());
        rowsDeleted = pstmt.executeUpdate();
        log.info("No of users deleted: " + rowsDeleted);
        return rowsDeleted;
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
        throw new DAOException(sqle.getMessage());
    }
}

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

private static String registerStructure(String classes, String method, String topic, String name,
        Structure structure) {/*from w w  w . j a va 2  s.  c o  m*/
    String ok = "ok";
    createDBConnection();
    PreparedStatement stp;
    try {
        System.out.println(name + " " + classes + " " + method + "  " + topic);
        stp = conn.prepareStatement("select data from \"Data\" where class=? and method=? ");
        stp.setString(1, classes);
        stp.setString(2, method);
        ResultSet result = stp.executeQuery();

        if (result.next()) {
            structures.put(name, structure);
            if (!result.getString(1).equals("Sensor")) {
                try {
                    stp = conn.prepareStatement(
                            "insert into \"Data\" (class, method, topic,data) values (?,?,?,?);");
                    stp.setString(1, classes);
                    stp.setString(2, method);
                    stp.setString(3, topic);
                    stp.setString(4, name);
                    stp.execute();
                } catch (SQLException e) {
                    String message = e.getMessage();
                    if (!message.contains("doppelter Schlsselwert")) {
                        stp = conn.prepareStatement(
                                "Update \"Data\" set data=? where class=? and method=? and topic=?");
                        stp.setString(1, name);
                        stp.setString(2, classes);
                        stp.setString(3, method);
                        stp.setString(4, topic);
                        stp.execute();
                    }
                }
                stp = conn.prepareStatement(
                        "update \"Controller\" set data=? where classoutput=? and methodoutput=? and topic=?;");
                stp.setString(1, name);
                stp.setString(2, classes);
                stp.setString(3, method);
                stp.setString(4, topic);
                stp.execute();
                controllerToList();
            }

        }

    } catch (SQLException e) {

        String message = e.getMessage();
        if (!message.contains("doppelter Schlsselwert")) {
            e.printStackTrace();
        } else {
            ok = "This method and topic has already a structure";
        }
    }

    closeDBConnection();
    return ok;
}

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

@Override
public int deleteUserPermission(CdwUserModel userModel, CdwPermissionModel cdwPermissionModel)
        throws DAOException {
    log.debug("deleteUserPermission(CdwUserModel userModel, CdwPermissionModel cdwPermissionModel) - start");
    StringBuffer query = new StringBuffer();
    query.append("DELETE FROM RDF_GRAPH_USER WHERE RGU_USER_ID = (SELECT U_ID FROM SYS_USERS WHERE U_NAME = ?) "
            + "AND RGU_GRAPH_IID = (SELECT RGG_IID from RDF_GRAPH_GROUP where RGG_IRI = ?)");

    try {//from w ww.j a  v  a 2 s . com
        // String graphGroupPrefix = CaCISUtil
        // .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_CDW_GRAPH_GROUP_URL_PREFIX);

        pstmt = new LoggableStatement(cacisConnection, query.toString());
        pstmt.setString(1, userModel.getUsername());
        // pstmt.setString(2, graphGroupPrefix + cdwPermissionModel.getStudyID() + "/"
        // + cdwPermissionModel.getSiteID() + "/" + cdwPermissionModel.getPatientID());
        pstmt.setString(2, cdwPermissionModel.getGraphGroupRGGIRI());
        log.info("SQL in deleteUserPermission(CdwUserModel userModel, CdwPermissionModel cdwPermissionModel): "
                + pstmt.toString());
        int rowsDeleted = pstmt.executeUpdate();
        log.info("No. of permissions deleted: " + rowsDeleted);

        return rowsDeleted;
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
        throw new DAOException(sqle.getMessage());
    }
}

From source file:ActualizadorLocal.Clientes.ClienteNodos.java

public void syncDB() {
    try {//w  ww. ja v  a2 s  . co m
        Statement st = conexion.crearSt();
        st.executeUpdate("INSERT INTO nodo (idNodo, nombre, latitud, longitud, poligono) VALUES" + cache
                + "ON DUPLICATE KEY UPDATE nombre=VALUES(nombre), latitud=VALUES(latitud), longitud=VALUES(longitud), poligono=VALUES(poligono); ");

    } catch (SQLException ex) {
        System.err.println(ex.getMessage());

    }
    cache_size = 0;
    cache = "";
}

From source file:eu.optimis.aggregator.test.AggregatorPushTest.java

private boolean deleteResources() {
    DBConnection dbconn = new DBConnection();
    Connection conn = dbconn.getConnection();
    String queryPhysical = null;/*from   w  ww  . j a va 2 s  . c o m*/
    String queryVirtual = null;
    queryPhysical = "Delete FROM  monitoring_resource_physical where physical_resource_id like '" + "%UnitTest%"
            + "'";
    queryVirtual = "Delete FROM  monitoring_resource_virtual where virtual_resource_id like '" + "%UnitTest%"
            + "'";
    try {
        Statement st = conn.createStatement();
        st.executeUpdate(queryPhysical);
        st.executeUpdate(queryVirtual);

    } catch (SQLException e) {
        logger.error("SQLException:" + e.getMessage() + ":" + e.getSQLState());
        return false;
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
        }
        ;
    }
    return true;
}

From source file:SessionLogin.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Login</title>");
    out.println("</head>");
    out.println("<body>");

    HttpSession session = request.getSession();
    SessionConnection sessionConnection = (SessionConnection) session.getAttribute("sessionconnection");
    Connection connection = null;
    if (sessionConnection != null) {
        connection = sessionConnection.getConnection();
    }/*  www  .  ja  v  a  2 s. co  m*/
    if (connection == null) {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        if (userName == null || password == null) {
            // prompt the user for her username and password
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("Please specify the following to log in:<p>");
            out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>");
            out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>");
            out.println("<input type=\"submit\" value=\"Login\">");
            out.println("</form>");
        } else {
            // create the connection
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName,
                        password);
            } catch (SQLException e) {
                out.println("Login doGet() " + e.getMessage());
            }
            if (connection != null) {
                // store the connection
                sessionConnection = new SessionConnection();
                sessionConnection.setConnection(connection);
                session.setAttribute("sessionconnection", sessionConnection);
                response.sendRedirect("SessionLogin");
                return;
            }
        }
    } else {
        String logout = request.getParameter("logout");
        if (logout == null) {
            // test the connection
            Statement statement = null;
            ResultSet resultSet = null;
            String userName = null;
            try {
                statement = connection.createStatement();
                resultSet = statement.executeQuery("select initcap(user) from sys.dual");
                if (resultSet.next())
                    userName = resultSet.getString(1);
            } catch (SQLException e) {
                out.println("Login doGet() SQLException: " + e.getMessage() + "<p>");
            } finally {
                if (resultSet != null)
                    try {
                        resultSet.close();
                    } catch (SQLException ignore) {
                    }
                if (statement != null)
                    try {
                        statement.close();
                    } catch (SQLException ignore) {
                    }
            }
            out.println("Hello " + userName + "!<p>");
            out.println("Your session ID is " + session.getId() + "<p>");
            out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>");
            out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>");
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">");
            out.println("</form>");
        } else {
            // close the connection and remove it from the session
            try {
                connection.close();
            } catch (SQLException ignore) {
            }
            session.removeAttribute("sessionconnection");
            out.println("You have been logged out.");
        }
    }
    out.println("</body>");
    out.println("</html>");
}

From source file:classes.Product.java

private int doUpdate(String query, String... params) {
    int rowAffected = 0;
    try (Connection connection = DatabaseConnection.connect()) {
        PreparedStatement pStatement = connection.prepareStatement(query);

        for (int i = 1; i <= params.length; i++) {
            pStatement.setString(i, params[i - 1]);
        }//from  w  ww  . j av a 2  s.  com
        rowAffected = pStatement.executeUpdate();
    } catch (SQLException ex)

    {
        System.err.println("SQL Exception" + ex.getMessage());
    }
    return rowAffected;
}

From source file:com.clustercontrol.sql.util.AccessDB.java

/**
 * ??SQL??//w ww  . j ava  2 s.  c om
 *
 * @param sql SQL
 * @return
 * @throws SQLException
 */
public ResultSet read(String sql) throws SQLException {
    ResultSet result = null;
    try {
        result = m_statement.executeQuery(sql);

    } catch (SQLException e) {
        m_log.info("read() database query failure : url = " + m_url + ", " + e.getClass().getSimpleName() + ", "
                + e.getMessage());
        throw e;
    }
    return result;
}