how to solve Invalid usage of the option NEXT in the FETCH statement I am using jtds 1.2.2 driver with SQL Server 2008. Below is the query I tried to execute 

SELECT * from AM_API  FETCH NEXT 10 ROWS ONLY


Anyway after executing above query I got below error

Caused by: java.sql.SQLException: Invalid usage of the option NEXT in the FETCH statement.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
    at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
    at org.jaggeryjs.hostobjects.db.DatabaseHostObject.executeQuery(DatabaseHostObject.java:510)


Any idea how to solve this issue?

UPDATE

I have read this that saying FETCH is working on SQL Server 2012 onwards only. Then how to limit result in SQL server 2008. The query going to execute is not under my control. I just postfixed FETCH NEXT 10 ROWS ONLY to the query to limit the result. So is there a way to limit the result by adding a limit query as a postfix to the query.
Upgrading to SQL Server 2012 will help but you'll still get the same error. From the documentation:

Limitations in Using OFFSET-FETCH:

ORDER BY is mandatory to use OFFSET and FETCH clause.
OFFSET clause is mandatory with FETCH. You can never use, ORDER BY … FETCH.


To return a non-deterministic 10 rows from your table you could do this in SQL Server 2012:
SELECT * 
FROM AM_API
ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

If you cannot upgrade you have a few additional options. SET ROWCOUNT is not deprecated for SELECT statements so the following should work on SQL Server 2008:
SET ROWCOUNT 10;

SELECT * 
FROM AM_API;

SET ROWCOUNT 0;

You could also use a TOP expression:
SELECT TOP 10 * 
FROM AM_API;