public static String addQueryLimit ( String queryString , int queryLimit ) { int limitIndex = queryString . lastIndexOf ( "limit" ) ; if ( limitIndex == - 1 ) { limitIndex = queryString . lastIndexOf ( "LIMIT" ) ; } if ( limitIndex == - 1 ) { return queryString + " LIMIT " + ( queryLimit + 1 ) ; } int limitNumber = Integer . parseInt ( queryString . substring ( limitIndex + 5 ) . trim ( ) ) ; return ( limitNumber > queryLimit ) ? queryString . substring ( 0 , limitIndex ) + " LIMIT " + ( queryLimit + 1 ) : queryString ; }
Limits query results .