gpt4 book ai didi

Java mysql 存储过程的下一个结果

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

我有以下存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `blast10`()
BEGIN
SELECT concat("ROUND ",draws.izvlacenje_id,": ", draws.1,",",draws.2,",",draws.3,",",draws.4,",",draws.5,",",draws.6,",",draws.7,",",draws.8,",",draws.9,",",draws.10,",",draws.11,",",draws.12,",",draws.13,",",draws.14,",\n",draws.15,",",draws.16,",",draws.17,",",draws.18,",",draws.19,",",draws.20,",",
draws.21,",",draws.22,",",draws.23,",",draws.24,",",draws.25,",",draws.26,",",draws.27,",",draws.28,",",draws.29,",",draws.30,",",draws.31,",",draws.32,",",draws.33,",",draws.34,",",draws.35,"")
rzlt from macau.draws order by iddraws desc limit 10;
END`

这个过程返回10行数据,我想通过TCP/IP通信发送这些数据,这是我现在实现的:

public void blastTen() throws SQLException {
String blastTen = "";
String bl10 = "LAST 10 RESULTS";
try {
Statement st = Conex.conn.createStatement();
String SQLEdit = "{ call blast10() }";
ResultSet rs = st.executeQuery(SQLEdit);
while (rs.next()) {
blastTen = bl10 + "\n" + rs.getString("rzlt") + "\n";
}
os.println(blastTen + "\n");
}
catch (Exception e2) {
System.out.println(e2);
}
}

问题是我只能发送一行,似乎无法获取其他行。

感谢任何帮助

最佳答案

代码

while (rs.next())
{
blastTen=bl10+"\n"+rs.getString("rzlt")+"\n";
}

不会向 bl10 分配任何内容,因此您始终只能获取最新行...尝试

   ...
bl10 = bl10 + "\n" + rs.getString( "rzlt" );
}
os.println( bl10 );

相反。

干杯,

关于Java mysql 存储过程的下一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26865767/

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