我有存储过程返回用户名的程序。我从 java(EclipseIDE)调用存储过程。存储过程的返回值为Null。如何避免这种Null
价值
这是我的存储过程
USE `employee`;
DROP procedure IF EXISTS `add1`;
DELIMITER $$
USE `employee`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `add1`(IN UserId int,
IN UserFirstName varchar(50),
IN UserLastName varchar(50),
IN Education varchar(50),
IN MarksInME int,
IN MarksInBE int,
IN MarksInPUC int,
IN Gender varchar(50),
OUT UserName varchar(50))
BEGIN
declare varName varchar(50);
select UserFirstName into varName from User where UserId=3516;
set UserName=varName;
insert into user(UserId,UserFirstName,UserLastName,Education,MarksInME,MarksInBE,MarksInPUC,Gender)
values(UserId,UserFirstName,UserLastName,Education,MarksInME,MarksInBE, MarksInPUC,Gender);
END$$
DELIMITER ;
我正在调用存储过程:
java.sql.CallableStatement cStmt = conn.prepareCall("{call add1(?,?,?,?,?,?,?,?,?)}");
cStmt.setInt(1,3541);
cStmt.setString(2,"pALLAVI");
cStmt.setString(3,"K");
cStmt.setString(4,"BE");
cStmt.setInt(5,0);
cStmt.setInt(6,60);
cStmt.setInt(7,600);
cStmt.setString(8,"chetana@gmail.com");
cStmt.registerOutParameter(9, java.sql.Types.VARCHAR);
cStmt.execute();
userName = cStmt.getString(9);
当我尝试打印UserName时,它打印为Null?
答案 0 :(得分:0)
UserId是硬编码的:
select UserFirstName into varName from User where UserId=3516;
请查看以下查询:
call add1(3541,'pALLAVI','K','BE',0,60,600,'chetana@gmail.com',@UserName);
SELECT @UserName;