Java调用MySQL存储过程并获得返回值的方法
程序员文章站
2024-03-04 18:42:24
本文实例讲述了java调用mysql存储过程并获得返回值的方法。分享给大家供大家参考。具体如下:
private void empsindept(connecti...
本文实例讲述了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(); }
希望本文所述对大家的java程序设计有所帮助。