Return multi-dataset notation:
First Kind
DROP PROCEDURE IF EXISTS' P_query_user '; DELIMITER// CREATE PROCEDUREP_query_user (p_inout_user_idINT ) begin DeclareCvarchar( -)default '0'; SELECT * fromT_sd_userWHERE user_id =p_inout_user_id; SETp_inout_user_id=2222;End //DELIMITER;Set @uId = the ; Call P_query_user (@uId );SELECT @uId;
The second Kind
Mysql>Delimiter//MySQL>Drop procedure if exists proc; MySQL>Create procedure proc()beginCreate Temporary TableTmp1 likeT;Insert intoTmp1Select * fromT;Create Temporary TableTmp2 likeT;Insert intoTmp2Select * fromT;End;//MySQL>delimiter; MySQL>Select * fromTmp1;mysql>Select * fromTMP2;
Note: Using temporary tables is always available at the session level, and calling the stored procedure again requires a drop of the staging table first.
Hibernate call
@Test Public voidtest0 () {Try{String Proceduresql= "Call P_query_user (: userId)"; SQLQuery sqlquery=t.getsession (). Createsqlquery (Proceduresql). Addentity (Tsduser.class); Object userId= 3000; Sqlquery.setparameter ("UserId", userId); List<TSdUser> result =sqlquery.list (); for(Tsduser tsduser:result) {System.out.println (tsduser); } System.out.println (UserId); } Catch(Exception e) {e.printstacktrace (); } }
The results are as follows:
Hibernate:call P_query_user (?)
Tsduser [usersysmlb=100.0, useruseredmlb=633137.0, userdodiscovercount=0, userdocommonssaycount=0, createtime=2014-05-08 12:20:35.0, lastactivatesystemmsgtime=2014-07-17 12:10:00.0, lastactivatesuscommentmsgtime=2014-05-08 12:20:35.0, LASTACTIVATENEGATIVEMSGTIME=2014-06-17 10:27:37.0, lastactivatepraisemsgtime=2014-05-08 12:20:35.0, LastActiveTime =2014-08-11 18:45:52.0, primsgtime=2014-08-09 14:30:27.0, Locktime=NULL, usermark=NULL, usersubmark=NULL, userremark=NULL, userinfo=NULL, userloginip=127.0.0.1, userlogginphonecode=13724770797, userregisterinfo=NULL, Userrealname=NULL, userregisterphonecode=13724770797, userregistrationcity=NULL, userphonecity= Zhanjiang, Userdevicetype=android, userloginqqid=1, userloginweixinid=NULL, userloginsinablogid=NULL, userweixinopenid=111, cteatetype=1, restaurantweixinopenid=222, WEIXINSUBSCRIBETIME=2014-05-17 13:29:28.0, Weixinsubscribestatus=subscribe, Weixinunsubscribetime=NULL, userid=3000, Username=mjorcen, Usertotalmlb=1.1111111e7, userdoattentioncount=0, userreattentioncount=0, Userdopraisecount=0, userrepraisecount=11, userdonegativecount=0, userrenegativecount=6, userDoShowDetailCount=38, Userdogetvouchercount=5, userdousedvouchercount=2, userphone=13724770797, Usergender=g, userGrade=0, userHeader= Null]
Or:
@Test Public voidtest1 () {Try{String Proceduresql= "Call P_query_user (?)"; Connection Connection=t.getsession (). connection (); Object userId= 3000; Java.sql.CallableStatement CS=connection. Preparecall (Proceduresql); Cs.setint (1, 3000); Cs.registeroutparameter ("P_INOUT_USER_ID", Types.integer); Cs.execute (); intPATAMS1 = Cs.getint (1); ResultSet ResultSet=Cs.getresultset (); while(Resultset.next ()) {System.out.println (Resultset.getint ("USER_ID")); } System.out.println (PATAMS1); } Catch(Exception e) {e.printstacktrace (); } }
An example on the Internet;
PublicString Callfirstprocedures (Final LongQyid,Final intPdys) {String Proceduresql= "{call GET_QYAQDCPDJB (?,?,?)}"; Object PJ=Jdbctemplate.execute (Proceduresql,NewCallableStatementCallback () { PublicObject doincallablestatement (CallableStatement cs)throwsSQLException, DataAccessException {cs.setlong (1, Qyid); Cs.setint (2, Pdys); //you need to register an output parameterCs.registeroutparameter (3, Types.varchar); Cs.execute (); returnCs.getstring (3); } }); returnHtmsutils.formatobject (PJ);}