这两天一直被一个获取时间的问题困扰,程序很简单执行存储过程从返回值中读取时间,如下:
reader = upDb.spExecuteReader(context, spName, spParams, values);
Date signTime = reader.getString("SignTime");
这样就会报错,[B cao not cast System.Util.Date
看数据字段定义的是TIMESTAMP没错。后来想了半天原来是存储过程用临时变量把类型给刷成byte数组了,存储过程类似如下:
DELIMITER $$
DROP PROCEDURE IF EXISTS `USP_test`$$
CREATE DEFINER=`admin`@`%` PROCEDURE `USP_test`(
)
BEGIN
SELECT SignTime INTO @SignTime FROM UP_SignQuota WHERE userid = 201266023;
SELECT @SignTime AS SignTime;
END$$
DELIMITER ;
修改为如下就可以:
DELIMITER $$
DROP PROCEDURE IF EXISTS `USP_test`$$
CREATE DEFINER=`admin`@`%` PROCEDURE `USP_test`(
)
BEGIN
SELECT SignTime FROM UP_SignQuota WHERE userid = 201266023;
END$$
如果改成直接读取值或不用临时变量就可以
reader = upDb.spExecuteReader(context, spName, spParams, values);
Date signTime = reader.getString("SignTime");
这样就会报错,[B cao not cast System.Util.Date
看数据字段定义的是TIMESTAMP没错。后来想了半天原来是存储过程用临时变量把类型给刷成byte数组了,存储过程类似如下:
DELIMITER $$
DROP PROCEDURE IF EXISTS `USP_test`$$
CREATE DEFINER=`admin`@`%` PROCEDURE `USP_test`(
)
BEGIN
SELECT SignTime INTO @SignTime FROM UP_SignQuota WHERE userid = 201266023;
SELECT @SignTime AS SignTime;
END$$
DELIMITER ;
修改为如下就可以:
DELIMITER $$
DROP PROCEDURE IF EXISTS `USP_test`$$
CREATE DEFINER=`admin`@`%` PROCEDURE `USP_test`(
)
BEGIN
SELECT SignTime FROM UP_SignQuota WHERE userid = 201266023;
END$$
如果改成直接读取值或不用临时变量就可以