欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

存储过程 带参数-java调用mysql存储过程输出参数

程序员文章站 2022-04-29 19:42:33
...
mysql存储过程 带参数java

CREATE PROCEDURE T_WEATHER_PRO (IN tmdn VARCHAR(12),OUT tmsg VARCHAR(12))

BEGIN

DECLARE states,beginTime,endTime VARCHAR(2) ;

SELECT T_STATES,T_BEGINTIME,T_ENDTIME INTO states,beginTime,endTime FROM T_USER_WEATHER WHERE T_USER = tmdn LIMIT 1;

IF states = NULL THEN

INSERT INTO T_USER_WEATHER VALUES(NULL,tmdn,1,7,10);

SELECT T_STATES,T_BEGINTIME,T_ENDTIME INTO states,beginTime,endTime FROM T_USER_WEATHER WHERE T_USER = tmdn LIMIT 1;

SET tmsg = states;

ELSE

SET tmsg = states;

END IF;

END;

java调用
Connection conn = MyDataSource.getConnection();
try {
CallableStatement cstmt=conn.prepareCall(sql);
cstmt.setString(1, "0985023223");
cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
cstmt.executeUpdate();
String result=cstmt.getString(2);
System.out.println(result);
} catch (SQLException e) {
// TODO Auto-generated catch blockxQ
e.printStackTrace();
}