In. NET, a dataset can automatically receive multiple result sets, forming a DataTable array.
Use Java, but also want to achieve this effect, Baidu a meal to find, finally find a solution.
Core method: CallableStatement ResultSet
Specific implementation code:
Import java.sql.CallableStatement;
Import Java.sql.ResultSet;
public void Search () {
String re = "";
String sql = "Call Pro1 (?,?);";
Connection con = dbconnpool.getconnection ();//Establish data connection to image
CallableStatement callsm = null;
try {
CALLSM = Con.preparecall (sql);
To pass a parameter to a stored procedure
Callsm.setstring (1, "res");
Callsm.setstring (2, "Me");
Executing stored procedures
Callsm.execute ();
Get result set
ResultSet rs = Callsm.getresultset ();
while (Rs.next ()) {
Re + = (re!= ""? ",": ") +rs.getstring (" ID ");
}
Re + = "|";
Determine if there is a second result set
if (Callsm.getmoreresults ()) {//This judgment will automatically point to the next result set
ResultSet rs1 = Callsm.getresultset ();
while (Rs1.next ()) {
Re + = (re!= ""? ",": "") +rs1.getstring ("q_id");
}
try {//close rs1
if (rs1!= null) {
Rs1.close ();
}
}
catch (Exception e) {
E.printstacktrace ();
}
}
try {//close rs1
if (Rs!= null) {
Rs.close ();
}
}
catch (Exception e) {
E.printstacktrace ();
}
System.out.println (re);
}
catch (Exception e) {
E.printstacktrace ();
}
finally {
try {
Callsm.close ();
Con.close ();
}
catch (Exception e) {
E.printstacktrace ();
}
}
}