`
WorkingHard?!
  • 浏览: 8776 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

P6Spy监控的spring jdbctemplate SQL语句输出

阅读更多
在采用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有时也会些“欺骗”行为:)
分享到:
评论
1 楼 yuzhibing 2009-01-05  
我用p6spy报错了。处理不了clob时段。郁闷~!@
那个高手,能小弟解决一下这个问题。qq:94597804

相关推荐

Global site tag (gtag.js) - Google Analytics