See the developer's guide - page 51, "Simple Dynamic SQL Elements".
Also, set the resultClass to java.util.HashMap to return a list of maps. (The list is implied when you use the queryForList() method). Jeff Butler On 8/7/07, Alec Lebedev <[EMAIL PROTECTED]> wrote: > > That worked, thanks. Is "parameter injection" feature documented > anywhere? > > > > Also, how come the following query returns a list with empty elements > instead of a list of lists or a list of maps? How can I read the result of > this query without creating a Java bean class for NP_USER table? > > > > <select id="selectTopUsers" resultClass="java.util.List" parameterClass=" > java.util.Map"> > > select top $max_users$ * from NP_USER > > </select> > > > > > ------------------------------ > > *From:* Niels Beekman [mailto:[EMAIL PROTECTED] > *Sent:* Tuesday, August 07, 2007 12:15 PM > *To:* [email protected] > *Subject:* RE: specifying offset/top parameter > > > > SQL Server does not allow top to be specified as a parameter, you need to > inject in the query: > > > > select top $max_users$ * from NP_USER > > > > HTH, > > > > Niels > ------------------------------ > > *From:* Alec Lebedev [mailto:[EMAIL PROTECTED] > *Sent:* dinsdag 7 augustus 2007 20:10 > *To:* [email protected] > *Subject:* specifying offset/top parameter > > > > I know that IBatis API allows the user to specify offset and max > parameters for a query, but is there a way to parameterize the number of > rows returned by the query in the XML query definition? When I use the > following query definition IBatis throws an exception thrown below. > > > > <select id="selectTopUsers" resultClass="java.util.List" parameterClass=" > java.util.Map"> > > select top #max_users# * from NP_USER > > </select> > > > > Exception in thread "main" * > com.ibatis.common.jdbc.exception.NestedSQLException*: > > --- The error occurred in ibatis/queries/UserReport.xml. > > --- The error occurred while applying a parameter map. > > --- Check the selectTopUsers-InlineParameterMap. > > --- Check the statement (query failed). > > --- Cause: *java.sql.SQLException*: Incorrect syntax near '@P0'. > > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback > (*GeneralStatement.java:185*) > > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList > (*GeneralStatement.java:123*) > > at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList > (*SqlMapExecutorDelegate.java:615*) > > at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList > (*SqlMapExecutorDelegate.java:589*) > > at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(* > SqlMapSessionImpl.java:118*) > > at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(* > SqlMapClientImpl.java:95*) > > at com.nextpage.server.domain.dao.IBatisReportDAO.selectTopUsers(* > IBatisReportDAO.java:40*) > > at com.nextpage.server.domain.dao.IBatisReportDAO.main(* > IBatisReportDAO.java:51*) > > Caused by: *java.sql.SQLException*: Incorrect syntax near '@P0'. > > at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(* > SQLDiagnostic.java:365*) > > at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(*TdsCore.java > :2781*) > > at net.sourceforge.jtds.jdbc.TdsCore.nextToken(*TdsCore.java:2224*) > > at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(*TdsCore.java > :628*) > > at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(* > JtdsStatement.java:525*) > > at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(* > JtdsStatement.java:487*) > > at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(* > JtdsPreparedStatement.java:475*) > > at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(* > SqlExecutor.java:186*) > > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery > (*GeneralStatement.java:205*) > > at > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback > (*GeneralStatement.java:173*) > > ... 7 more > > >
