2 gww761562 gww761562 于 2014.08.25 15:24 提问

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

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

1个回答

shendixiong
shendixiong   2014.08.25 18:06
select tmsg ;

这样就可以了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!