我对 DAO 类和 StoredProcedure 有一个奇怪的问题,发生的事情是我使用了一个带有CallableStatement
15 个IN
参数的对象,该字段的值id_color
是从 HTML 表单中正确检索的,它甚至在设置CallableStatement
器中设置了它应该如何设置方法,但是当它被发送到数据库时,它被这里的“上下文”id_color
的值覆盖3
:我有以下DAO.CoverDAO
处理CRUD
这个表的操作的类
CREATE TABLE `cover_details` (
`refno` int(10) unsigned NOT NULL AUTO_INCREMENT,
`shape` tinyint(3) unsigned NOT NULL ,
`id_color` tinyint(3) unsigned NOT NULL ',
`reversefold` bit(1) NOT NULL DEFAULT b'0' ,
`x` decimal(6,3) unsigned NOT NULL ,
`y` decimal(6,3) unsigned NOT NULL DEFAULT '0.000',
`typecut` varchar(10) NOT NULL,
`cornershape` varchar(20) NOT NULL,
`z` decimal(6,3) unsigned DEFAULT '0.000' ,
`othercornerradius` decimal(6,3) unsigned DEFAULT '0.000'',
`skirt` decimal(5,3) unsigned NOT NULL DEFAULT '7.000',
`foamTaper` varchar(3) NOT NULL,
`foamDensity` decimal(2,1) unsigned NOT NULL ,
`straplocation` char(1) NOT NULL ',
`straplength` decimal(6,3) unsigned NOT NULL,
`strapinset` decimal(6,3) unsigned NOT NULL,
`spayear` varchar(20) DEFAULT 'Not Specified',
`spamake` varchar(20) DEFAULT 'Not Specified',
`spabrand` varchar(20) DEFAULT 'Not Specified',
PRIMARY KEY (`refno`)
) ENGINE=MyISAM AUTO_INCREMENT=143 DEFAULT CHARSET=latin1 $$
插入封面的方式是通过存储过程,如下所示:
CREATE DEFINER=`root`@`%` PROCEDURE `putCover`(
IN shape TINYINT,
IN color TINYINT,
IN reverse_fold BIT,
IN x DECIMAL(6,3),
IN y DECIMAL(6,3),
IN type_cut VARCHAR(10),
IN corner_shape VARCHAR(10),
IN cutsize DECIMAL(6,3),
IN corner_radius DECIMAL(6,3),
IN skirt DECIMAL(5,3),
IN foam_taper VARCHAR(7),
IN foam_density DECIMAL(2,1),
IN strap_location CHAR(1),
IN strap_length DECIMAL(6,3),
IN strap_inset DECIMAL(6,3)
)
BEGIN
INSERT INTO `dbre`.`cover_details`
(`dbre`.`cover_details`.`shape`,
`dbre`.`cover_details`.`id_color`,
`dbre`.`cover_details`.`reversefold`,
`dbre`.`cover_details`.`x`,
`dbre`.`cover_details`.`y`,
`dbre`.`cover_details`.`typecut`,
`dbre`.`cover_details`.`cornershape`,
`dbre`.`cover_details`.`z`,
`dbre`.`cover_details`.`othercornerradius`,
`dbre`.`cover_details`.`skirt`,
`dbre`.`cover_details`.`foamTaper`,
`dbre`.`cover_details`.`foamDensity`,
`dbre`.`cover_details`.`strapLocation`,
`dbre`.`cover_details`.`strapInset`,
`dbre`.`cover_details`.`strapLength`
)
VALUES
(shape,color,reverse_fold,
x,y,type_cut,corner_shape,
cutsize,corner_radius,skirt,foam_taper,foam_density,
strap_location,strap_inset,strap_length);
END
正如你所看到的,它基本上只是填充了每个字段,现在,CoverDAO.create(CoverDTO cover)
创建封面的方法如下:
public void create(CoverDTO cover) throws DAOException {
Connection link = null;
CallableStatement query = null;
try {
link = MySQL.getConnection();
link.setAutoCommit(false);
query = link.prepareCall(
"{CALL putCover(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"
);
query.setByte(1,cover.getShape().byteValue());
query.setByte(2,cover.getColor().byteValue());
query.setBoolean(3, cover.getReverseFold());
query.setBigDecimal(4,cover.getX());
query.setBigDecimal(5,cover.getY());
query.setString(6,cover.getTypeCut());
query.setString(7,cover.getCornerShape());
query.setBigDecimal(8, cover.getZ());
query.setBigDecimal(9, cover.getCornerRadius());
query.setBigDecimal(10, cover.getSkirt());
query.setString(11, cover.getFoamTaper());
query.setBigDecimal(12, cover.getFoamDensity());
query.setString(13, cover.getStrapLocation());
query.setBigDecimal(14, cover.getStrapLength());
query.setBigDecimal(15, cover.getStrapInset());
query.executeUpdate();
link.commit();
} catch (SQLException e) {
throw new DAOException(e);
} finally {
close(link, query);
}
}
CoverDTO 由访问方法组成,MySQL 对象基本上从池中返回连接。
这是带有虚拟但适当数据的 pset 查询:(
putCover(1,10,0,80.0,80.0,'F','Cut',0.0,0,15.0,'4x2',1.5,'A',10.0,5.0)
删除了一些尾随零)正如您所见,当我写入数据库而不是写入10
第二个参数 a时,一切都很好3
。我做了以下事情:
id_color
到 create 方法,仍然被替换为 3