MySQL程序保持返回0

时间:2017-03-24 14:06:38

标签: java mysql

不知道为什么,但我一直把0作为输出参数...... 我运行了以下内容:

INSERT INTO users (first_name, last_name, email, image, date_of_registration)
 VALUES ("xx", "xx", "xxx", null, sysdate());SELECT LAST_INSERT_ID();

我得到了好结果(!= 0),而不是假设PersistentConnections设置为true。任何其他可能造成这种情况的配置?

程序

DROP PROCEDURE IF EXISTS partners.create_user;
CREATE DEFINER=`partnersmaster`@`%` PROCEDURE `create_user`(
  IN p_first_name NVARCHAR(30),
  IN p_last_name NVARCHAR(30),
  IN p_email NVARCHAR(100),
  IN p_image NVARCHAR(200),
  IN p_date_of_registration TIMESTAMP,
  OUT p_user_id INT
  )
BEGIN
    INSERT INTO users (first_name, last_name, email, image, date_of_registration)
    VALUES (p_first_name, p_last_name, p_email, p_image, p_date_of_registration);
    SET @p_user_id = LAST_INSERT_ID();
END;

爪哇

conn = engine.getDal().getConnection();
st = conn.prepareCall("{call partners.create_user(?,?,?,?,?,?)}");
st.setString("p_first_name", user.getFirstName());
st.setString("p_last_name", user.getLastName());
st.setString("p_email", user.getEmail());
if(user.getImage() != null)
    st.setString("p_image", user.getImage());
else
    st.setNull("p_image", Types.NVARCHAR);
st.setTimestamp("p_date_of_registration", new Timestamp(System.currentTimeMillis()));
st.registerOutParameter("p_user_id", Types.INTEGER);
st.execute();
userId = st.getInt("p_user_id");

1 个答案:

答案 0 :(得分:0)

过程参数和会话变量存在问题 - startAt(String value) vs p_user_id。在您的情况下,@p_user_id未设置。

以这种方式更改代码 -

p_user_id