当前位置: 首页>>代码示例>>Java>>正文


Java BadSqlGrammarException类代码示例

本文整理汇总了Java中org.springframework.jdbc.BadSqlGrammarException的典型用法代码示例。如果您正苦于以下问题:Java BadSqlGrammarException类的具体用法?Java BadSqlGrammarException怎么用?Java BadSqlGrammarException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BadSqlGrammarException类属于org.springframework.jdbc包,在下文中一共展示了BadSqlGrammarException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readAccessTokenFromSecureStore

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
private OAuth2AccessToken readAccessTokenFromSecureStore(String tokenKey) {
    if (tokenKey.length() > TOKEN_KEY_MAX_LENGTH) {
        throw new IllegalArgumentException(Messages.TOKEN_KEY_FORMAT_NOT_VALID);
    }

    SqlParameter storeNameParam = new SqlParameter(Types.VARCHAR);
    SqlParameter forXsApplicationUserParam = new SqlParameter(Types.BOOLEAN);
    SqlParameter keyParam = new SqlParameter(Types.VARCHAR);
    SqlOutParameter valueParam = new SqlOutParameter("VALUE", Types.VARBINARY);

    List<SqlParameter> paramList = Arrays.asList(storeNameParam, forXsApplicationUserParam, keyParam, valueParam);
    Map<String, Object> result = null;
    try {
        result = callRetrieve(tokenKey, paramList, PROCEDURE_SECURESTORE_RETRIEVE);
    } catch (BadSqlGrammarException e) {
        throwIfShouldNotIgnore(e, RETRIEVE_PROCEDURE_NAME);
        result = callRetrieve(tokenKey, paramList, PROCEDURE_SECURESTORE_RETRIEVE_LEGACY);
    }
    byte[] tokenBytes = (byte[]) result.get("VALUE");
    if (tokenBytes == null) {
        throw new IllegalArgumentException(Messages.TOKEN_NOT_FOUND_IN_SECURE_STORE);
    }
    byte[] decompressedBytes = CompressUtil.decompress(tokenBytes);
    OAuth2AccessToken accessToken = TokenUtil.createToken(new String(decompressedBytes, StandardCharsets.UTF_8));
    return accessToken;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:27,代码来源:HanaSecureTokenStore.java

示例2: doTranslate

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	String sqlState = getSqlState(ex);
	if (sqlState != null && sqlState.length() >= 2) {
		String classCode = sqlState.substring(0, 2);
		if (logger.isDebugEnabled()) {
			logger.debug("Extracted SQL state class '" + classCode + "' from value '" + sqlState + "'");
		}
		if (BAD_SQL_GRAMMAR_CODES.contains(classCode)) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:SQLStateSQLExceptionTranslator.java

示例3: handleUncaughtException

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@ResponseBody
@Order(Ordered.HIGHEST_PRECEDENCE)
@ExceptionHandler(Throwable.class)
public final ResponseEntity<Result<String>> handleUncaughtException(final Throwable exception, final WebRequest
        request) {
    // adds information about encountered error to application log
    LOG.error(MessageHelper.getMessage("logger.error", request.getDescription(true)), exception);
    HttpStatus code = HttpStatus.OK;

    String message;
    if (exception instanceof FileNotFoundException) {
        // any details about real path of a resource should be normally prevented to send to the client
        message = MessageHelper.getMessage("error.io.not.found");
    } else if (exception instanceof DataAccessException) {
        // any details about data access error should be normally prevented to send to the client,
        // as its message can contain information about failed SQL query or/and database schema
        if (exception instanceof BadSqlGrammarException) {
            // for convenience we need to provide detailed information about occurred BadSqlGrammarException,
            // but it can be retrieved
            SQLException root = ((BadSqlGrammarException) exception).getSQLException();
            if (root.getNextException() != null) {
                LOG.error(MessageHelper.getMessage("logger.error.root.cause", request.getDescription(true)),
                    root.getNextException());
            }
            message = MessageHelper.getMessage("error.sql.bad.grammar");
        } else {
            message = MessageHelper.getMessage("error.sql");
        }
    } else if (exception instanceof UnauthorizedClientException) {
        message = exception.getMessage();
        code = HttpStatus.UNAUTHORIZED;
    } else {
        message = exception.getMessage();
    }

    return new ResponseEntity<>(Result.error(StringUtils.defaultString(StringUtils.trimToNull(message),
                                   MessageHelper.getMessage("error" + ".default"))), code);
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:39,代码来源:ExceptionHandlerAdvice.java

示例4: customErrorCodeTranslation

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
@SuppressWarnings("resource")
public void customErrorCodeTranslation() {
	new ClassPathXmlApplicationContext("test-custom-translators-context.xml",
			CustomSQLExceptionTranslatorRegistrarTests.class);

	SQLErrorCodes codes = SQLErrorCodesFactory.getInstance().getErrorCodes("H2");
	SQLErrorCodeSQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator();
	sext.setSqlErrorCodes(codes);

	DataAccessException exFor4200 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 42000));
	assertNotNull("Should have been translated", exFor4200);
	assertTrue("Should have been instance of BadSqlGrammarException",
		BadSqlGrammarException.class.isAssignableFrom(exFor4200.getClass()));

	DataAccessException exFor2 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 2));
	assertNotNull("Should have been translated", exFor2);
	assertTrue("Should have been instance of TransientDataAccessResourceException",
		TransientDataAccessResourceException.class.isAssignableFrom(exFor2.getClass()));

	DataAccessException exFor3 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 3));
	assertNull("Should not have been translated", exFor3);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CustomSQLExceptionTranslatorRegistrarTests.java

示例5: testSQLErrorCodeTranslation

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void testSQLErrorCodeTranslation() throws Exception {
	final SQLException sqlException = new SQLException("I have a known problem", "99999", 1054);
	final String sql = "SELECT ID FROM CUSTOMER";

	given(this.resultSet.next()).willReturn(true);
	mockDatabaseMetaData(false);
	given(this.connection.createStatement()).willReturn(this.preparedStatement);

	this.thrown.expect(BadSqlGrammarException.class);
	this.thrown.expect(exceptionCause(sameInstance(sqlException)));
	try {
		this.template.query(sql, new RowCallbackHandler() {
			@Override
			public void processRow(ResultSet rs) throws SQLException {
				throw sqlException;
			}
		});
		fail("Should have thrown BadSqlGrammarException");
	}
	finally {
		verify(this.resultSet).close();
		verify(this.preparedStatement).close();
		verify(this.connection, atLeastOnce()).close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:JdbcTemplateTests.java

示例6: testNoSuchStoredProcedure

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void testNoSuchStoredProcedure() throws Exception {
	final String NO_SUCH_PROC = "x";
	SQLException sqlException = new SQLException("Syntax error or access violation exception", "42000");
	given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
	given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
	given(databaseMetaData.getUserName()).willReturn("me");
	given(databaseMetaData.storesLowerCaseIdentifiers()).willReturn(true);
	given(callableStatement.execute()).willThrow(sqlException);
	given(connection.prepareCall("{call " + NO_SUCH_PROC + "()}")).willReturn(callableStatement);
	SimpleJdbcCall sproc = new SimpleJdbcCall(dataSource).withProcedureName(NO_SUCH_PROC);
	thrown.expect(BadSqlGrammarException.class);
	thrown.expect(exceptionCause(sameInstance(sqlException)));
	try {
		sproc.execute();
	}
	finally {
		verify(callableStatement).close();
		verify(connection, atLeastOnce()).close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SimpleJdbcCallTests.java

示例7: loadData

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Override
public void loadData() {
	String sql = "select * from " + tableName;
	List<DynamicEnumRecord> list;
	try {
		list = jdbc.queryForList(sql, DynamicEnumRecord.class);
	}
	catch (BadSqlGrammarException e) {
		return;
	}
	logger.info("loadData list:" + list);

	data.clear();
	for (DynamicEnumRecord record : list) {
		String enumId = record.getEnumId();
		data.put(enumId, record);
	}
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:19,代码来源:DynamicEnumDaoJdbcImpl.java

示例8: get

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
public ModelVersion get(String modelName) {
    Object o = null;

    SelectStatementCreator sel = new SelectStatementCreator();
    sel.setValues(modelName);
    try {
        o = jdbc.query(sel, extractor);
    } catch (BadSqlGrammarException ex) {
        try {
            // try simples query possible to see if table exists
            jdbc.queryForInt("SELECT count(*) FROM " + tableName);

            // some other kind of error
            throw ex;
        } catch (BadSqlGrammarException ex2) {
            log.debug("previous install not found: " + ex2.getMessage());
            o = null;
        }
    }
    if (o == null) {
        ModelVersion mv = new ModelVersion(modelName);
        log.debug("created: " + mv);
        return mv;
    }
    return (ModelVersion) o;
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:27,代码来源:ModelVersionDAO.java

示例9: testInitializationDisabled

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void testInitializationDisabled() throws Exception {
	this.context.register(DataSourceAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	DataSource dataSource = this.context.getBean(DataSource.class);
	this.context.publishEvent(new DataSourceInitializedEvent(dataSource));
	assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
	assertThat(dataSource).isNotNull();
	JdbcOperations template = new JdbcTemplate(dataSource);
	try {
		template.queryForObject("SELECT COUNT(*) from BAR", Integer.class);
		fail("Query should have failed as BAR table does not exist");
	}
	catch (BadSqlGrammarException ex) {
		SQLException sqlException = ex.getSQLException();
		int expectedCode = -5501; // user lacks privilege or object not found
		assertThat(sqlException.getErrorCode()).isEqualTo(expectedCode);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:DataSourceInitializerTests.java

示例10: testInitializationDisabled

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void testInitializationDisabled() throws Exception {
	this.context.register(DataSourceAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();

	DataSource dataSource = this.context.getBean(DataSource.class);

	this.context.publishEvent(new DataSourceInitializedEvent(dataSource));

	assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
	assertThat(dataSource).isNotNull();
	JdbcOperations template = new JdbcTemplate(dataSource);

	try {
		template.queryForObject("SELECT COUNT(*) from BAR", Integer.class);
		fail("Query should have failed as BAR table does not exist");
	}
	catch (BadSqlGrammarException ex) {
		SQLException sqlException = ex.getSQLException();
		int expectedCode = -5501; // user lacks privilege or object not found
		assertThat(sqlException.getErrorCode()).isEqualTo(expectedCode);
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:25,代码来源:DataSourceInitializerTests.java

示例11: createViewTable

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Override
public String createViewTable( SqlView sqlView )
{
    dropViewTable( sqlView );

    final String sql = TYPE_CREATE_PREFIX_MAP.get( sqlView.getType() ) + statementBuilder.columnQuote( sqlView.getViewName() ) + " AS " + sqlView.getSqlQuery();

    log.debug( "Create view SQL: " + sql );

    try
    {
        jdbcTemplate.execute( sql );

        return null;
    }
    catch ( BadSqlGrammarException ex )
    {
        return ex.getCause().getMessage();
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:21,代码来源:HibernateSqlViewStore.java

示例12: getEventCount

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Override
public long getEventCount( EventQueryParams params )
{
    String sql = "select count(psi) ";
    
    sql += getFromWhereClause( params );
    
    long count = 0;
    
    try
    {
        log.debug( "Analytics event count SQL: " + sql );
        
        count = jdbcTemplate.queryForObject( sql, Long.class );
    }
    catch ( BadSqlGrammarException ex )
    {
        log.info( QUERY_ERR_MSG, ex );
    }
    
    return count;
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:23,代码来源:JdbcEventAnalyticsManager.java

示例13: test_update_rollback

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void test_update_rollback() {
  DbLegalEntityBeanMaster w = new DbLegalEntityBeanMaster(_lenMaster.getDbConnector());
  w.setElSqlBundle(ElSqlBundle.of(new ElSqlConfig("TestRollback"), DbBeanMaster.class));
  final LegalEntityDocument base = _lenMaster.get(UniqueId.of("DbLen", "101", "0"));
  UniqueId uniqueId = UniqueId.of("DbLen", "101", "0");
  ManageableLegalEntity legalEntity = new MockLegalEntity("TestLegalEntity", ExternalIdBundle.of("A", "B"), Currency.GBP);
  legalEntity.setUniqueId(uniqueId);
  LegalEntityDocument input = new LegalEntityDocument(legalEntity);
  try {
    w.update(input);
    Assert.fail();
  } catch (BadSqlGrammarException ex) {
    // expected
  }
  final LegalEntityDocument test = _lenMaster.get(UniqueId.of("DbLen", "101", "0"));

  assertEquals(base, test);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:20,代码来源:ModifyDbLegalEntityBeanMasterTest.java

示例14: test_update_rollback

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void test_update_rollback() {
  DbPositionMaster w = new DbPositionMaster(_posMaster.getDbConnector());
  w.setElSqlBundle(ElSqlBundle.of(new ElSqlConfig("TestRollback"), DbPositionMaster.class));
  final PositionDocument base = _posMaster.get(UniqueId.of("DbPos", "121", "0"));
  ManageablePosition pos = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
  pos.setUniqueId(UniqueId.of("DbPos", "121", "0"));
  PositionDocument input = new PositionDocument(pos);
  try {
    w.update(input);
    Assert.fail();
  } catch (BadSqlGrammarException ex) {
    // expected
  }
  final PositionDocument test = _posMaster.get(UniqueId.of("DbPos", "121", "0"));
  
  assertEquals(base, test);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:ModifyPositionDbPositionMasterWorkerUpdatePositionTest.java

示例15: test_update_rollback

import org.springframework.jdbc.BadSqlGrammarException; //导入依赖的package包/类
@Test
public void test_update_rollback() {
  DbSecurityMaster w = new DbSecurityMaster(_secMaster.getDbConnector());
  w.setElSqlBundle(ElSqlBundle.of(new ElSqlConfig("TestRollback"), DbSecurityMaster.class));
  final SecurityDocument base = _secMaster.get(UniqueId.of("DbSec", "101", "0"));
  UniqueId uniqueId = UniqueId.of("DbSec", "101", "0");
  ManageableSecurity security = new ManageableSecurity(uniqueId, "Name", "Type", ExternalIdBundle.of("A", "B"));
  SecurityDocument input = new SecurityDocument(security);
  try {
    w.update(input);
    Assert.fail();
  } catch (BadSqlGrammarException ex) {
    // expected
  }
  final SecurityDocument test = _secMaster.get(UniqueId.of("DbSec", "101", "0"));
  
  assertEquals(base, test);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:ModifySecurityDbSecurityMasterWorkerUpdateTest.java


注:本文中的org.springframework.jdbc.BadSqlGrammarException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。