简体   繁体   English

存储过程中没有带有JDBC临时表的ResultSet

[英]No ResultSet from stored procedure with temporary table with JDBC

I have a stored procedure which creates a temp table and populates the temp table. 我有一个存储过程,该过程创建一个临时表并填充该临时表。 After populating it, it returns the rows inside the table with ( SELECT ). 填充后,它使用( SELECT )返回表内的行。

When running it from MySQL workbench works tremendously but in JAVA with JDBC, the ResultSet is empty. 从MySQL工作台运行时,它的工作原理非常好,但是在具有JDBC的JAVA中,ResultSet为空。 I have gone through some posts which say that we should not use PreparedStatment but even Statement doesn't work. 我浏览了一些帖子,说我们不应该使用PreparedStatment但即使Statement也不能使用。

For test, I divided the job in stored procedure. 为了进行测试,我将工作划分为存储过程。 Now I call: 现在我打电话给:

CallableStatement ps = connection.prepareCall("{CALL myProcedure(?)}");
ps.setString(1, "value");
ps.execute();

which creates the temp table and populates it. 这将创建并填充临时表。 Thereafter with same connection I try to do 之后,我尝试相同的连接

Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM tmp_table");

Still ResultSet is empty. 仍然ResultSet为空。 What can I do? 我能做什么? Any help is appreciated. 任何帮助表示赞赏。

Thank you folks for help! 谢谢大家的帮助! I found the error. 我发现了错误。 The error was in code. 错误出在代码中。

I send a parameter when calling procedure. 我在调用过程时发送参数。 For testing purposes I did 出于测试目的,我做了

SET @param = "value";

Later on, I removed it but I forgot to remove it when inserting data into temporary table which used that @param . 后来,我删除了它,但是在将数据插入使用该@param临时表中时忘记了删除它。 MySQL somehow could see that @param and IN param is same because of name but JDBC could not see that and Therefore, it was not returning any data. MySQL以某种方式可以看到@paramIN param由于名称而相同,但是JDBC却没有看到,因此,它没有返回任何数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM