List of usage examples for org.springframework.jdbc.core JdbcOperations queryForObject
@Nullable
<T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException;
From source file:com.nortal.petit.core.util.OracleSqlUtil.java
public static Long getSequenceNextValue(String sequenceName, JdbcOperations jdbcTemplate) { return jdbcTemplate.queryForObject("SELECT " + sequenceName + ".nextval AS nextval FROM DUAL", Long.class); }
From source file:org.springframework.jdbc.core.simple.SimpleJdbcTemplateTests.java
public void testQueryForObjectWithoutArgs() throws Exception { String sql = "SELECT SYSDATE FROM DUAL"; Date expectedResult = new Date(); MockControl mc = MockControl.createControl(JdbcOperations.class); JdbcOperations jo = (JdbcOperations) mc.getMock(); jo.queryForObject(sql, Date.class); mc.setReturnValue(expectedResult);// www . ja va 2s . co m mc.replay(); SimpleJdbcTemplate jth = new SimpleJdbcTemplate(jo); Date result = jth.queryForObject(sql, Date.class); assertEquals(expectedResult, result); mc.verify(); }
From source file:org.springframework.jdbc.core.simple.SimpleJdbcTemplateTests.java
public void testQueryForObjectWithRowMapperAndWithoutArgs() throws Exception { String sql = "SELECT SYSDATE FROM DUAL"; Date expectedResult = new Date(); ParameterizedRowMapper<Date> rm = new ParameterizedRowMapper<Date>() { public Date mapRow(ResultSet rs, int rowNum) { return new Date(); }/*from w w w.j a v a 2 s .com*/ }; MockControl mc = MockControl.createControl(JdbcOperations.class); JdbcOperations jo = (JdbcOperations) mc.getMock(); jo.queryForObject(sql, rm); mc.setReturnValue(expectedResult); mc.replay(); SimpleJdbcTemplate jth = new SimpleJdbcTemplate(jo); Date result = jth.queryForObject(sql, rm); assertEquals(expectedResult, result); mc.verify(); }