I am trying to implement a task in Java using JDBC as a stored procedure in SQL. In SQL, when we write the cursor, we first execute the select query, and then select the records and perform some actions.
I probably ran a fetch request in Hive.
sql="SELECT a,c,b FROM tbl_name"; res=stmt.executeQuery(); -----------> CONTAINS 30 RECORDS while(res.next()) { sql="INSERT INTO table ....."; rs1=stmt.executeQuery(); sql="SELECT d,e,f FROM table ....."; rs1=stmt.executeQuery(); like wise many queries are there..... . . . .. }
Since my fetch request contains 30 records, but when I execute it, while (res.next ()) time is executed only once.
But instead of asking, I'm just trying to display a field to check if it selects or not, then it works fine .. (although the loop contains only System.out.println statements)
sql="SELECT * FROM tbl_name"; res=stmt.executeQuery(sql); while(res.next()) { SOP("fields : "+res.getString(0)); }
(I think that when there is a revision of the result set, and if there is between the requests, then the requests receive execution, but at the same time, the cycle also receives execution, and after a while, when the execution of the requests ends with it, while the result set cycle also ends and therefore it is executed once. I am not sure about that.)
Why this is happening, I do not understand. Is something I am doing wrong?