Java 調用 MySQL 存儲過程并獲得返回值
private void empsInDept(Connection myConnect, int deptId) throws SQLException {
CallableStatement cStmt = myConnect.prepareCall(\"{CALL sp_emps_in_dept(?)}\");
cStmt.setInt(1, deptId);
cStmt.execute();
ResultSet rs1 = cStmt.getResultSet();
while (rs1.next()) {
System.out.println(rs1.getString(\"department_name\") + \" \"
+ rs1.getString(\"location\"));
}
rs1.close();
/ process second result set /
if (cStmt.getMoreResults()) {
ResultSet rs2 = cStmt.getResultSet();
while (rs2.next()) {
System.out.println(rs2.getInt(1) + \" \" + rs2.getString(2) + \" \"
+ rs2.getString(3));
}
rs2.close();
}
cStmt.close();
}
</pre>
本文由用戶 eb5y 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!