gpt4 book ai didi

java - 带有多个paramsin java mysql的PreparedStatement问题

转载 作者:行者123 更新时间:2023-11-29 05:19:23 27 4
gpt4 key购买 nike

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

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).

关于java - 带有多个paramsin java mysql的PreparedStatement问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27924117/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com