public < T > T getSingleResult ( Class < T > clazz , String sql , Object [ ] params ) { PreparedStatement stmt = null ; ResultSet rs = null ; try { stmt = connectionProvider . getConnection ( ) . prepareStatement ( sql ) ; setParameters ( stmt , params ) ; if ( logger . isDebugEnabled ( ) ) { printSql ( sql ) ; printParameters ( params ) ; } rs = stmt . executeQuery ( ) ; ResultSetMetaData meta = rs . getMetaData ( ) ; int columnCount = meta . getColumnCount ( ) ; BeanDesc beanDesc = beanDescFactory . getBeanDesc ( clazz ) ; if ( rs . next ( ) ) { T entity = entityOperator . createEntity ( clazz , rs , meta , columnCount , beanDesc , dialect , valueTypes , nameConverter ) ; return entity ; } return null ; } catch ( SQLException ex ) { throw new SQLRuntimeException ( ex ) ; } finally { JdbcUtil . close ( rs ) ; JdbcUtil . close ( stmt ) ; } }
Returns a single entity from the first row of an SQL .