当前位置:Gxlcms > mysql > 存储过程带参数-java调用mysql存储过程输出参数

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

时间:2021-07-01 10:21:17 帮助过:99人阅读

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();
}

人气教程排行