带有多个参数的 PreparedStatement 问题 java mysql

Issue With PreparedStatement with multiple paramsin java mysql

我正在使用以下代码段从 select 查询中检索有限数量的原始数据。

String query="SELECT * FROM smsmessage WHERE recipient = ? LIMIT ?";
   PreparedStatement prepStmt = conn.prepareStatement(query);
   prepStmt.setString(1,shortCode);
   prepStmt.setString(2,batchSize);
   ResultSet rs=prepStmt.executeQuery();

但它给了我以下问题

 ERROR {com.axiata.plugin.ReceiveSMS.ReceiveSMSNotification} -  MySQL exception   
 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
 You have an error in your SQL     syntax; check the manual that corresponds
to your MySQL  server version for the right syntax to use near ''2'' at line 1

我的代码段有没有错误?我不能像上面那样使用多个参数吗?

LIMIT 子句需要 int

prepStmt.setInt(2, Integer.parseInt(batchSize));

SELECT 从 MySQL 文档读取(部分)

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 (except when using prepared statements).