Example usage for org.springframework.jdbc BadSqlGrammarException getMessage

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

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.jicai.db.impl.AbstractJiCaiDBExtractService.java

/**
 * ??//from w w w.j  a  v a  2s.com
 */
private SystemVO internalGetSchemas(String schema, int start, int limit, boolean flag) throws Exception {
    try {
        //?ODS?
        SRC_NME = properties.getProperty("SRC_NME");
        SystemVO sysInfo = new SystemVO();
        List<SchemaVO> schemasVO = new ArrayList<SchemaVO>();
        //???
        sysInfo.setSysName(properties.getProperty("sysName"));
        //???
        sysInfo.seteSysName(properties.getProperty("ESysName"));
        //?schemaName????
        SchemaVO schemasvo = new SchemaVO();
        List<TableVO> tables = null;
        if (flag) {
            tables = getTables(schema, start, limit);
        } else {
            tables = new ArrayList<TableVO>();
        }
        log.info("?:" + tables.size());
        //??
        List<ColumnVO> fields = getFields(schema, start, limit);
        log.info("?:" + fields.size());
        schemasvo.setTables(tables);
        schemasvo.setFields(fields);
        schemasvo.setSchName(schema);
        schemasVO.add(schemasvo);
        sysInfo.setSchemas(schemasVO);
        return sysInfo;
    } catch (BadSqlGrammarException e) {
        if (e.getMessage().indexOf(signOfNoPrivilege()) > -1) {
            log.warn("???????:"
                    + getSystemTableList().toString(), e);
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR,
                    "???????:"
                            + getSystemTableList().toString());
        }
        throw e;
    }
}

From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.db.impl.AbstractDBExtractService.java

/**
 * ??//from   ww  w . j  av  a2  s  .  c  o  m
 */
private List<Schema> internalGetSchemas() throws SQLException {
    try {
        List<Schema> schemas = getSchemas();
        for (int i = 0; schemas != null && i < schemas.size(); i++) {
            Schema schema = schemas.get(i);
            String schName = schema.getName();
            String dataType = getMetadata().getDatabaseProductName();
            if (dataType.equals("PostgreSQL")) {
                schName = schName.toLowerCase();
            }
            log.info("schema:" + schName);
            schema.addColumnSet(internalGetTables(schName));
            schema.addColumnSet(internalGetViews(schName));
            schema.setMacros(getMacro(schName));
            schema.setProcedures(internalGetProcedures(schName));
            schema.setTriggers(getTriggers(schName));
            schema.setSQLIndexs(internalGetIndexs(schName));
        }
        return schemas;
    } catch (BadSqlGrammarException e) {
        if (e.getMessage().indexOf(signOfNoPrivilege()) > -1) {
            log.warn("???????:"
                    + getSystemTableList().toString(), e);
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR,
                    "???????:"
                            + getSystemTableList().toString());
        }
        throw e;
    }
}

From source file:com.blackducksoftware.tools.appedit.naiaudit.dao.jdbc.JdbcVulnNaiAuditDetailsDao.java

/**
 * Get a map containing all NAI Audit Details for the given application.
 *
 * @param applicationId/*from  w w  w. j  av  a  2 s .c  o  m*/
 * @return
 * @throws AppEditException
 */
@Override
public Map<AppCompVulnKey, VulnNaiAuditDetails> getVulnNaiAuditDetailsMap(final String applicationId) {

    final String SQL = SQL_SELECT_ALL_VULNERABILITIES_FOR_APP;
    final SqlParameterSource namedParameters = new MapSqlParameterSource("appId", applicationId);
    logger.debug("Getting vulnNaiAuditDetails for appID " + applicationId + "; SQL: " + SQL);

    List<VulnNaiAuditDetails> vulnNaiAuditDetailsList = null;
    try {
        vulnNaiAuditDetailsList = jdbcTemplate.query(SQL, namedParameters, new VulnNaiAuditDetailsMapper());
    } catch (final BadSqlGrammarException e) {
        final String msg = "Error getting NAI Audit details. Make sure the NAI Audit database tables have been created. Details: "
                + e.getMessage();
        logger.error(msg);
        throw new IllegalStateException(msg);
    }

    logger.debug("Read " + vulnNaiAuditDetailsList.size() + " vulnNaiAuditDetail records.");
    final Map<AppCompVulnKey, VulnNaiAuditDetails> vulnNaiAuditDetailsMap = new HashMap<>();
    for (final VulnNaiAuditDetails vulnNaiAuditDetails : vulnNaiAuditDetailsList) {
        logger.info("VulnNaiAuditDetails: " + vulnNaiAuditDetails);
        vulnNaiAuditDetailsMap.put(vulnNaiAuditDetails.getAppCompVulnKey(), vulnNaiAuditDetails);
    }
    return vulnNaiAuditDetailsMap;
}

From source file:com.blackducksoftware.tools.appedit.naiaudit.dao.jdbc.JdbcVulnNaiAuditDetailsDao.java

@Override
public VulnNaiAuditDetails getVulnNaiAuditDetails(final AppCompVulnKey key) throws AppEditException {

    final String SQL = SQL_FETCH_ONE_VULNERABILITY_BY_KEY;
    final Map<String, String> paramMap = new HashMap<>();
    paramMap.put("appId", key.getApplicationId());
    paramMap.put("compUseId", key.getRequestId());
    paramMap.put("compId", key.getComponentId());
    paramMap.put("vulnId", key.getVulnerabilityId());
    final SqlParameterSource namedParameters = new MapSqlParameterSource(paramMap);
    logger.debug("Getting vulnNaiAuditDetails for key " + key + "; SQL: " + SQL);

    List<VulnNaiAuditDetails> vulnNaiAuditDetailsList = null;
    try {/*from w ww  .  ja  va2  s .  c o  m*/
        vulnNaiAuditDetailsList = jdbcTemplate.query(SQL, namedParameters, new VulnNaiAuditDetailsMapper());
    } catch (final BadSqlGrammarException e) {
        final String msg = "Error getting NAI Audit details for vulnerability. Make sure the NAI Audit database tables have been created. Details: "
                + e.getMessage();
        logger.error(msg);
        throw new IllegalStateException(msg);
    }

    logger.debug("Read " + vulnNaiAuditDetailsList.size() + " vulnNaiAuditDetail records.");

    if (vulnNaiAuditDetailsList.size() == 0) {
        logger.warn("No NAI Audit details record found for key: " + key);
        return null;
    } else if (vulnNaiAuditDetailsList.size() > 1) {
        final String msg = "The NAI Audit details contains " + vulnNaiAuditDetailsList.size()
                + "records with key " + key + "; it should contains at most one";
        logger.error(msg);
        throw new IllegalStateException(msg);
    }

    return vulnNaiAuditDetailsList.get(0);
}

From source file:om.edu.squ.squportal.portlet.dps.study.extension.db.ExtensionDbImpl.java

/**
 * /*from w w w.  jav  a  2s. c om*/
 * method name  : setExtensionByStudent
 * @param extensionDTO
 * @return
 * ExtensionDbImpl
 * return type  : int
 * 
 * purpose      :   Insert to extension as student
 *
 * Date          :   Jan 24, 2017 2:02:28 PM
 */
public int setExtensionByStudent(ExtensionDTO extensionDTO) {
    String SQL_EXTENSION_INSERT_STUDENT = queryExtensionProps
            .getProperty(Constants.CONST_SQL_EXTENSION_INSERT_STUDENT);
    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramStdNo", extensionDTO.getStudentNo());
    namedParameterMap.put("paramStdStatCode", extensionDTO.getStdStatCode());
    namedParameterMap.put("paramFromYearCode", extensionDTO.getFromCcYrCode());
    namedParameterMap.put("paramFromSemCode", extensionDTO.getFromSemCode());
    namedParameterMap.put("paramToYearCode", extensionDTO.getToCcYrCode());
    namedParameterMap.put("paramToSemCode", extensionDTO.getToSemCode());
    namedParameterMap.put("paramUserCode", extensionDTO.getUserCode());
    namedParameterMap.put("paramExtReasonCode", extensionDTO.getReasonCode());
    namedParameterMap.put("paramExtReasonOther", extensionDTO.getReasonOther());
    namedParameterMap.put("paramExtStatusCode", Constants.CONST_SQL_STATUS_CODE_NAME_PENDING);

    try {
        return nPJdbcTemplDpsExtension.update(SQL_EXTENSION_INSERT_STUDENT, namedParameterMap);
    } catch (BadSqlGrammarException sqlEx) {
        logger.error("Error in Database record insert :: details : {}", sqlEx.getMessage());
        return 0;
    }
}

From source file:om.edu.squ.squportal.portlet.dps.registration.postpone.db.PostponeDBImpl.java

/**
 * /* ww  w .ja  v  a 2s.  c o m*/
 * method name  : setPostponeByStudent
 * @param dto
 * @return
 * PostponeDBImpl
 * return type  : int
 * 
 * purpose      : Insert to postpone as student
 *
 * Date          :   Aug 7, 2017 5:00:53 PM
 */
public int setPostponeByStudent(PostponeDTO dto) {
    String SQL_POSTPONE_INSERT_STUDENT = queryPostpone.getProperty(Constants.CONST_SQL_POSTPONE_INSERT_STUDENT);

    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramStdNo", dto.getStudentNo());
    namedParameterMap.put("paramStdStatCode", dto.getStudentStatCode());
    namedParameterMap.put("paramFromYearCode", dto.getFromCcYearCode());
    namedParameterMap.put("paramFromSemCode", dto.getFromSemCode());
    namedParameterMap.put("paramToYearCode", dto.getToCcYearCode());
    namedParameterMap.put("paramToSemCode", dto.getToSemCode());
    namedParameterMap.put("paramPostponeReasonCode", dto.getReasonCode());
    namedParameterMap.put("paramPostponeReasonOther", dto.getReasonOther());
    namedParameterMap.put("paramPostponeStatusCode", Constants.CONST_SQL_STATUS_CODE_NAME_PENDING);
    namedParameterMap.put("paramUserCode", dto.getUserName());

    try {
        return nPJdbcTemplDpsPostpone.update(SQL_POSTPONE_INSERT_STUDENT, namedParameterMap);
    } catch (BadSqlGrammarException sqlEx) {
        logger.error("Error in Database record insert :: details : {}", sqlEx.getMessage());
        return 0;
    }

}

From source file:om.edu.squ.squportal.portlet.dps.registration.dropw.db.DropWDBImpl.java

/**
 * /* www . j  a  v a2 s .  co  m*/
 * method name  : setDropWCourseWithdrawProc
 * @param dropWDTO
 * @return
 * DropWDBImpl
 * return type  : int
 * 
 * purpose      :
 *
 * Date          :   May 7, 2017 10:36:17 AM
 */
@Transactional
private Map setDropWCourseWithdrawProc(DropWDTO dropWDTO) throws NotSuccessFulDBUpdate {
    Map resultProc = null;

    simpleJdbcCallDpsDropW.withProcedureName(Constants.CONST_PROC_DROPW_WITHDRAW_COURSE);
    simpleJdbcCallDpsDropW.withoutProcedureColumnMetaDataAccess();
    simpleJdbcCallDpsDropW.useInParameterNames(Constants.CONST_PROC_COL_NAME_P_STDNO,
            Constants.CONST_PROC_COL_NAME_P_SECTCD, Constants.CONST_PROC_COL_NAME_P_SECTNO,
            Constants.CONST_PROC_COL_NAME_P_USER);
    simpleJdbcCallDpsDropW.declareParameters(
            new SqlParameter(Constants.CONST_PROC_COL_NAME_P_STDNO, Types.NUMERIC),
            new SqlParameter(Constants.CONST_PROC_COL_NAME_P_SECTCD, Types.NUMERIC),
            new SqlParameter(Constants.CONST_PROC_COL_NAME_P_SECTNO, Types.NUMERIC),
            new SqlParameter(Constants.CONST_PROC_COL_NAME_P_USER, Types.VARCHAR)

    );
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put(Constants.CONST_PROC_COL_NAME_P_STDNO, dropWDTO.getStudentNo());
    paramMap.put(Constants.CONST_PROC_COL_NAME_P_SECTCD, dropWDTO.getSectCode());
    paramMap.put(Constants.CONST_PROC_COL_NAME_P_SECTNO, dropWDTO.getSectionNo());
    paramMap.put(Constants.CONST_PROC_COL_NAME_P_USER, dropWDTO.getUserName());

    try {
        resultProc = simpleJdbcCallDpsDropW.execute(paramMap);
    } catch (BadSqlGrammarException badGrException) {
        logger.error("Might be a grammatical issue in stored procedure");
        throw new NotSuccessFulDBUpdate(badGrException.getMessage());
    } catch (UncategorizedSQLException exception) {
        logger.error("Course drop not successful for student no : {}, course no {} . Details : {} - {}",
                dropWDTO.getStudentNo(), dropWDTO.getCourseNo(), exception.getSQLException().getErrorCode(),
                exception.getSQLException().getMessage());
        throw new NotSuccessFulDBUpdate(exception.getMessage());

    }

    return resultProc;
}

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

/**
 * ? Exception ? ?  ??   ??  ? .//from w  ww.j ava2 s .  com
 * @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:org.projectforge.test.TestConfiguration.java

/**
 * Init and reinitialise context for each run
 *///from w w w .  j  a  v a  2s  .c om
protected void initCtx() throws BeansException {
    if (ctx == null) {
        log.info("Initializing context: "
                + org.projectforge.common.StringHelper.listToString(", ", contextFiles));
        try {
            // Build spring context
            ctx = new ClassPathXmlApplicationContext(contextFiles);
            ctx.getBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME,
                    false);

            final PropertyDataSource ds = ctx.getBean("dataSource", PropertyDataSource.class);
            this.databaseUrl = ds.getUrl();
            final JdbcTemplate jdbc = new JdbcTemplate(ds);
            try {
                jdbc.execute("CHECKPOINT DEFRAG");
            } catch (final org.springframework.jdbc.BadSqlGrammarException ex) {
                // ignore
            }
            final LocalSessionFactoryBean localSessionFactoryBean = (LocalSessionFactoryBean) ctx
                    .getBean("&sessionFactory");
            HibernateUtils.setConfiguration(localSessionFactoryBean.getConfiguration());
        } catch (final Throwable ex) {
            log.error(ex.getMessage(), ex);
            throw new RuntimeException(ex);
        }
    } else {
        // Get a new HibernateTemplate each time
        ctx.getBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    }
    final Configuration cfg = ctx.getBean("configuration", Configuration.class);
    cfg.setBeanFactory(ctx.getBeanFactory()); // Bean factory need to be set.
}