Java mysql接下来是存储过程的结果

时间:2014-11-11 13:13:11

标签: java mysql sockets

我有以下存储过程:

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);
    }
}

问题是我只能发送一行而且似乎无法获得其他行。

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

代码

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

不会为bl10分配任何内容,因此您始终只会获得最新的一行...尝试

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

代替。

干杯,