Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view the real SQL under Grails

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to view the real SQL under Grails". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to view the real SQL under Grails"!

In the past, we used to open sql in hibernate. In grails, we only need to add a dataSource in DataSource.groovy.

LogSql = true is fine, but the SQL issued after this addition goes like this, insert into t_user values (?) Can't you see? The value in it

If I want to see the real value in it, that is: insert into t_user values.

Just use log4jdbc. The steps are as follows:

1. Download log4jdbc4-1.2.1.jar and add it to lib (see attachment)

two。 Add a bean to the grails-app/conf/spring/resources.groovy file for spring to manage, as follows:

Beans = {log4jdbcInterceptor (net.sf.log4jdbc.DataSourceSpyInterceptor) dataSourceLog4jdbcAutoProxyCreator (org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator) {interceptorNames = 'log4jdbcInterceptor' beanNames =' dataSource'}}

3. Enable support for log4jdbc in log4j. Add the following to log4j in grails-app/conf/Config.groovy:

Off 'jdbc.sqlonly',' jdbc.audit', 'jdbc.resultset',' jdbc.connection' info 'jdbc.sqltiming'

Now try again in your project and you can see the real SQL.

2011-07-04 11 0012 443 [http-8090-3] INFO jdbc.sqltiming-

Select

Count (*) as y0_

From

User this_ {executed in 16 msec}

At this point, I believe you have a deeper understanding of "how to view the real SQL under Grails". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report