Use LIMIT to paginate results in MySQL query

前端 未结 3 899
迷失自我
迷失自我 2020-12-10 17:05

I want to fetch my results a \'page\' at a time; I want the page number to be a parameter (in a JDBC prepared statement). Consider the following snippet

SELE         


        
3条回答
  •  悲哀的现实
    2020-12-10 17:42

    MySQL requires numeric constants for that LIMIT syntax.

    From http://dev.mysql.com/doc/refman/5.7/en/select.html:

    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions:

    • Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.

    • Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.

    Compute the constant on the Java side.

提交回复
热议问题