Ibatis calling stored procedures and MySQL creating stored procedures

Source: Internet
Author: User
Tags sql error

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");} 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.