DELIMITER // the DROP PROCEDURE MyProc // - deletion process the CREATE PROCEDURE MyProc (the IN P1 int , P2 INOUT int , OUT P3 int ) the BEGIN the SELECT p1, p2, p3; - output p1, p2, p3 content of the SET P1 = 10 ; the SET P2 = 20 is ; the SET P3 = 30 ; the END // DELIMITER; the SET @ X1 = 70; - definition of variables x1, content 70 the SET @ X2 = 80; - definition of variables x2, content 80 the CALL MyProc (@ X1, X2 @, @ X3); the SELECT @ X1, X2 @, @ X3;
Import the java.sql.Connection; Import the java.sql.DriverManager; Import java.sql.SQLException; Import java.sql.CallableStatement Sets; Import the java.sql.Types; public class ProcDemo { // database driver defines the MySQL public static Final dbDriver = String "the org.gjt.mm.mysql.Driver" ; // connect MySQL database address defines public static Final String dburl = "JDBC: MySQL: // localhost: 3306 / MLDN" ; // connecting user MySQL database name public static Final String DBUSER = "root"; // connection password MySQL database public static Final String = DBPASS in "mysqladmin" ; public static void main (String args []) throws Exception { // all exceptions thrown Connection Conn = null ; // database connection CallableStatement cstmt = null ; // database operation String SQL = "{MyProc the cALL (,,???)}"; // call procedure the Class.forName (dbDriver); // load drivers conn =The DriverManager.getConnection (dburl, with DBUSER, DBPASS in); cstmt = conn.prepareCall (SQL); cstmt.setInt ( 1,70); // set the first parameter is 70 cstmt.setInt (2,80); // Set the second parameter is 80 cstmt.registerOutParameter (2 , Types.INTEGER); cstmt.registerOutParameter ( . 3 , Types.INTEGER); cstmt.execute (); // execution System.out.println ( "INOUT return value: "+ cstmt.getInt (2 )); System.out.println ( " OUT return value: "+ cstmt.getInt (. 3 )); cstmt.close (); conn.Close (); // close the database } };