Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-06 09:44:15
Original
1434 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!