论坛首页 Java企业应用论坛

P6Spy监控的spring jdbctemplate SQL语句输出

浏览 2979 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-11  
在采用p6spy监控sql语句时,可以查看到preparedstatement中使用?来表现的具体的值,当直接使用preparedstatement时,可以指定传入的变量值的类型,如下:
PreparedStatement ps = con.prepareStatement("select * from user where id=?:)
ps.setLong(1,new Long(100));

这时通过p6spy监控的sql语句为:
select * from user where id=100


如果采用spring jdbctemplate对数据库进行操作,代码如下:
jdbcTemplate.queryForObject("select * from user where id=?", new Object[]{new Long(100)}, new int[]{Types.BIGINT});

这时同通过p6spy监控的sql语句为:
select * from user where id='100'

但是通过跟踪springtemplate源代码发现,指定的参数类型Types.BIGINT已经传入了参数设定的方法中,值为-5,也按照相应的类型进行了设置,相当于执行了
ps.setLong(1,new Long(100));

但是p6spy并没有输出
select * from user where id=100

当使用p6spy监控Hibernate同样的方法生成的语句时也能够正确的输出:
select * from user where id=100


看来p6spy有时也会些“欺骗”行为:)
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics