Example usage for org.springframework.jdbc BadSqlGrammarException getSQLException

List of usage examples for org.springframework.jdbc BadSqlGrammarException getSQLException

Introduction

In this page you can find the example usage for org.springframework.jdbc BadSqlGrammarException getSQLException.

Prototype

public SQLException getSQLException() 

Source Link

Document

Return the wrapped SQLException.

Usage

From source file:sample.flyway.SampleFlywayApplicationTests.java

@Test
public void should_have_the_last_name_column_removed_from_db() throws Exception {
    try {/*from   w ww  . j a va 2 s .co  m*/
        assertEquals(new Integer(1),
                this.template.queryForObject("SELECT COUNT(last_name) from PERSON", Integer.class));
        fail();
    } catch (BadSqlGrammarException e) {
        assertTrue(e.getSQLException().getMessage().contains("Column \"LAST_NAME\" not found;"));
    }
}

From source file:com.bbm.common.aspect.ExceptionTransfer.java

/**
 * ? Exception ? ?  ??   ??  ? .// w  ww  .  j ava 2  s  . c  o  m
 * @param thisJoinPoint joinPoint ?
 * @param exception ? Exception 
 */
public void transfer(JoinPoint thisJoinPoint, Exception exception) throws Exception {
    log.debug("execute ExceptionTransfer.transfer ");

    Class clazz = thisJoinPoint.getTarget().getClass();
    Signature signature = thisJoinPoint.getSignature();

    Locale locale = LocaleContextHolder.getLocale();
    /**
     * BizException ?  ??     ? ?.
     * Exception   ?? ? ?? Exception? ? ? ?.
     *   ?    . 
     * ?   ??  Handler     ?  ?.
     */

    String servicename = ""; //  
    String errorCode = ""; // ? 
    String errorMessage = ""; // ? 
    String classname = ""; // ??  

    int servicepos = clazz.getCanonicalName().lastIndexOf("."); //   .? 
    if (servicepos > 0) {
        String tempStr = clazz.getCanonicalName().substring(servicepos + 1);
        servicepos = tempStr.lastIndexOf("Impl"); //   Impl? 
        servicename = tempStr.substring(0, servicepos);
    } else {
        servicename = clazz.getCanonicalName();
    }
    classname = exception.getClass().getName();

    //EgovBizException ? ? 
    if (exception instanceof EgovBizException) {
        log.debug("Exception case :: EgovBizException ");

        EgovBizException be = (EgovBizException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception . (runtime ?  ExceptionHandlerService )
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        throw be;

        //RuntimeException ? ? ? DataAccessException ?   ?? throw  .
    } else if (exception instanceof RuntimeException) {
        log.debug("RuntimeException case :: RuntimeException ");

        RuntimeException be = (RuntimeException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception .
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        if (be instanceof DataAccessException) {
            /*
            log.debug("RuntimeException case :: DataAccessException ");
            DataAccessException sqlEx = (DataAccessException) be;
            throw sqlEx;
            */
            log.debug("RuntimeException case :: DataAccessException ");

            DataAccessException dataEx = (DataAccessException) be;
            Throwable t = dataEx.getRootCause();
            String exceptionname = t.getClass().getName();

            if (exceptionname.equals("java.sql.SQLException")) {
                java.sql.SQLException sqlException = (java.sql.SQLException) t;
                errorCode = String.valueOf(sqlException.getErrorCode());
                errorMessage = sqlException.getMessage();
            } else if (exception instanceof org.springframework.jdbc.BadSqlGrammarException) {
                org.springframework.jdbc.BadSqlGrammarException sqlEx = (org.springframework.jdbc.BadSqlGrammarException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.UncategorizedSQLException) {
                org.springframework.jdbc.UncategorizedSQLException sqlEx = (org.springframework.jdbc.UncategorizedSQLException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) {
                org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException sqlEx = (org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) exception;
                errorCode = String.valueOf(sqlEx.getActualRowsAffected());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.SQLWarningException) {
                org.springframework.jdbc.SQLWarningException sqlEx = (org.springframework.jdbc.SQLWarningException) exception;
                errorCode = String.valueOf(sqlEx.SQLWarning().getErrorCode());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) {
                org.springframework.jdbc.CannotGetJdbcConnectionException sqlEx = (org.springframework.jdbc.CannotGetJdbcConnectionException) exception;
                errorCode = String.valueOf(sqlEx.getMessage());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.InvalidResultSetAccessException) {
                org.springframework.jdbc.InvalidResultSetAccessException sqlEx = (org.springframework.jdbc.InvalidResultSetAccessException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else {

                if (exception instanceof java.lang.reflect.InvocationTargetException) {

                    java.lang.reflect.InvocationTargetException ce = (java.lang.reflect.InvocationTargetException) exception;
                    errorCode = "";
                    errorMessage = ce.getTargetException().getMessage();
                    //strErrorMessage = getValue(ce.getTargetException().toString(), "");

                }
            }

            //  , ?, ?, ,  
            String[] messages = new String[] { "DataAccessException", errorCode, errorMessage, servicename,
                    signature.getName(), classname };
            throw processException(clazz, "fail.common.msg", messages, exception, locale);
        }

        //  , ?, ?, ,  
        errorMessage = exception.getMessage();
        String[] messages = new String[] { "RuntimeException", errorCode, errorMessage, servicename,
                signature.getName(), classname };
        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw be;

        // ? ? Exception (: ) :: ?  ?.
    } else if (exception instanceof FdlException) {
        log.debug("FdlException case :: FdlException ");

        FdlException fe = (FdlException) exception;
        getLog(clazz).error(fe.getMessage(), fe.getCause());
        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "FdlException", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw fe;

    } else {
        //? ? Exception ?  BaseException (: fail.common.msg)     ?. 
        //:: ?  ?.
        log.debug("case :: Exception ");

        getLog(clazz).error(exception.getMessage(), exception.getCause());

        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "Exception", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);

    }
}

From source file:rapture.repo.jdbc.JDBCStructuredStore.java

@Override
public Boolean createProcedureCallUsingSql(CallingContext context, String rawSql) {

    try {//w  ww .  ja v a2  s. c  o m
        // TODO RAP-3548 Need to parse rawSql and check entitlements

        // Execute query
        jdbc.execute(rawSql);
        return true;
    } catch (BadSqlGrammarException e) {
        log.error(e.getSQLException());
        return false;
    }
}

From source file:rapture.repo.jdbc.JDBCStructuredStore.java

@Override
public StoredProcedureResponse callProcedure(CallingContext context, String procName,
        StoredProcedureParams params) {/*from ww w  . j  a  va 2 s .c  o  m*/

    // TODO RAP-3548 Need to check entitlements

    SimpleJdbcCall call = new SimpleJdbcCall(jdbc).withProcedureName(procName)
            .withoutProcedureColumnMetaDataAccess();
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    Map<String, Object> inParams = (params == null) ? null : params.getInParams();
    Map<String, Integer> outParams = (params == null) ? null : params.getOutParams();
    Map<String, Object> inOutParams = (params == null) ? null : params.getInOutParams();

    if (inParams != null) {
        // Declare Parameters
        Map<String, Integer> inParamTypes = getInputParamTypes(inParams);
        for (Map.Entry<String, Integer> entry : inParamTypes.entrySet()) {
            call.declareParameters(new SqlParameter(entry.getKey(), entry.getValue()));
        }

        // Give Input Parameters
        for (Map.Entry<String, Object> entry : inParams.entrySet()) {
            paramSource.addValue(entry.getKey(), entry.getValue());
        }
    }

    if (inOutParams != null) {
        Map<String, Integer> inOutParamTypes = getInputParamTypes(inOutParams);
        for (Map.Entry<String, Integer> entry : inOutParamTypes.entrySet()) {
            call.declareParameters(new SqlInOutParameter(entry.getKey(), entry.getValue()));
        }

        // Give Input Parameters
        for (Map.Entry<String, Object> entry : inOutParams.entrySet()) {
            paramSource.addValue(entry.getKey(), entry.getValue());
        }
    }

    if (outParams != null) {
        for (Map.Entry<String, Integer> entry : outParams.entrySet()) {
            call.declareParameters(new SqlOutParameter(entry.getKey(), entry.getValue()));
        }
    }

    try {
        return packageStoredProcedureReturn(call.execute(paramSource), true);
    } catch (BadSqlGrammarException e) {
        log.error(e.getSQLException());
        return packageStoredProcedureReturn(null, false);
    }

}

From source file:rapture.repo.jdbc.JDBCStructuredStore.java

@Override
public Boolean dropProcedureUsingSql(CallingContext context, String rawSql) {

    try {/*from w  w  w  .  ja va2  s . co  m*/
        // TODO RAP-3548 Need to parse rawSql and check entitlements

        // Execute query
        jdbc.execute(rawSql);
        return true;
    } catch (BadSqlGrammarException e) {
        log.error(e.getSQLException());
        return false;
    }
}