First, the SQL that created the stored procedure in MySQL
--List all stored procedures show PROCEDURE status;--to view the creation statement for an existing stored procedure, and if this stored procedure does not exist, it will prompt for a SQL error (1305): PROCEDURE Pro_init does not existshow Create PROCEDURE pro_init;--Creating stored Procedure drop PROCEDURE IF EXISTS pro_init; --Delete an existing stored procedure delimiter//--declares that the current MySQL delimiter is//create PROCEDURE pro_init (username VARCHAR), out US Erid INT) Beginselect user_id into userId from User_info UI WHERE ui.username=username;if userId is NULL OR userid= ' Thens Elect 0 into UserId; Elseinsert into T_worldcup_team (userid, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES (userid, ' Brazil ', ' Russia ', NULL, now ()) INSERT into T_worldcup_team (userid, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES (userid, ' France ', ' Spain ', NULL, Now ()); I Nsert into T_worldcup_team (userid, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES (userid, ' Holland ', ' England ', NULL, Now ()); Nsert into T_worldcup_team (userid, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES (userid, ' Chile ', ' Italy ', NULL, Now ()); Nsert into T_worldcup_team (UserId, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES (userid, ' Iran ', ' Portugal ', NULL, Now ()); INSERT into T_worldcup_team (userid, Teamaa, TEAMBB, UpdateTime, Createtime) VALUES ( UserId, ' Greek ', ' Argentina ', NULL, Now ()); END IF; end//--delimiter, which indicates the end of this SQL statement--calls the stored procedure call Pro_init (' Hongyu ', @userId); SELECT @userId;
here is how the Ibatis configuration file is written
<parametermap id= "Pro_init_map" class= "Java.util.Map" ><parameter property= "username" javatype= " Java.lang.String "jdbctype=" VARCHAR "mode=" in "/><parameter property=" userId "javatype=" Java.lang.Integer " Jdbctype= "INT" mode= "Out"/></parametermap><procedure id= "Pro_init" parametermap= "Pro_init_Map" >{ Call Pro_init (?,?)} </procedure>
and finally, the Java calling class.
public int Teaminit (String username) {int userId = 0; map<string, object> parammap = new hashmap<string, object> ();p arammap.put ("username", username); Parammap.put ("userid", UserID); This.getsqlmapclienttemplate (). queryForObject ("Worldcup_guess.pro_init", ParamMap ); return (Integer) parammap.get ("UserId");}