【发布时间】:2010-07-19 14:14:10
【问题描述】:
我正在使用 simpleJDBCTemplate 向 postgre 数据库插入一个值。
String sql "insert into testTable values(:bla, :blah, functionThatTakesAText(':blu'))"
BeanPropertySqlParameterSource namedParameters = new BeanPropertySqlParameterSource(lighting);
simpleJdbcTemplate.update(sql, namedParameters);
现在,blu 参数实际上是一个从客户端提供的文件中读取的数字(实际的 sql 需要 2 个实数)。
因此,数据库会收到如下内容:
insert into testTable values(?, ?, functionThatTakesAText(':blu'))
并且未能按预期替换 :blu 参数。
我正在使用的当前解决方法是使用正则表达式将 blu 参数替换为其值,但我不确定这有多安全。
你会怎么解决这个问题?
【问题讨论】: