1. HIBERNATE怎样查看sql语句
弄hibernate时,想显示sql语句,可以设置show_sql为true来达到这个目的,但是参数值全是像PreparedStatement一样,用?来代替的。用p6spy可以达到显示的那些参数原值的目的,但可读性差。可以利用SQL Profiler来处理这个事情。p6spy: http://www.p6spy.com/SQL Profile: http://www.jahia.net/jahia/page597.htmlp6spy安装:* 将p6spy.jar放到WEB-INF/lib目录下,将spy.properties放到WEB-INF/classes目录下。* 修改你 原有 JDBC Driver为:com.p6spy.engine.spy.P6SpyDriver* 修改 spy.properties 中的 realdriver 值为 原有 的JDBC Driver,比如我的是:com.mysql.jdbc.Driver* 完成,运行web server。我的日志记录产生在 %TOMCAT_HOME%\bin下,此log位置可以能过修改 logfile = x:\x_dir\spy.log 来控制打开看看,看里面的日志是不是看起来比较不爽?下面我们安装SQL Profiler来让自已的视线爽一点。SQL Profiler安装:(须p6spy成功安装)* 将SQL Profiler自带的spy.properties覆盖原来的classes目录下文件* 修改现在spy.properties中realdriver 值为 原有 的JDBC Driver看后看看readme注意这几句 ^__^ :1. Start the GUI2. Start the webapp, in starts doing some JDBC requests we will ignore3. Press the "reset" button on the GUI4. Make a request to the webapp5. Press the "pause" button after the request has finished executing6. Press the "report" button to save profiling results as a CSV file* 我们先用java -jar sqlprofiler.jar 运行 sql profiler* 然后启动web server :-)一切尽在眼前了吧?
2. hibernate怎么在控制台显示sql语句
找到hibernate的配置文件-- hibernate.cfg.xml
加入:
<property name="hibernate.show_sql">true</property>
如果你用spring那么就要:
修改spring里面的配置文件:
...
<property name="hibernateProperties">
<props>
<prop key = "hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key = "hibernate.show_sql">false</prop>
3. 怎样把hibernate产生的SQL语句,输出到log4j文件
怎样把hibernate产生的SQL语句,输出到log4j文件
因为hibernate在输出sql时使用的logger名为org.hibernate.SQL,所以想让SQL语句输出到log4j,只要在log4j.properties或log4j.xml的配置中加上如下语句:
log4j.logger.org.hibernate.SQL=DEBUG
记得同时把hibernate中配置文件hibernate.show_sql设置为false,避免同时在控制台和log日志中双份输出sql语句。
4. 怎样配置能让hibernate生成查询sql语句时,自动加上
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>//这一行就是关键,有了它就会显示运行时的sql语句
</props>
</property>
5. hibernate中配置了show sql ,可是控制台不打印sql ,有哪些原因
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
6. 有关hibernate.show_sql
这个和数据库没关系
hibernate3.2好像是用slf4j记录数据
不过得转换成LOG4J记录
然后 去log4j的properties文件改 让hibernate打印sql
7. hibernate怎么显示sql语句
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="com/chenhui/bean/TUserLogin.hbm.xml" />
<mapping resource="com/chenhui/bean/TUserContent.hbm.xml" />
<mapping resource="com/chenhui/bean/TComment.hbm.xml" />
<mapping resource="com/chenhui/bean/TVideo.hbm.xml" />
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/video
</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.show_sql">true</property><!-- 配置显示sql语句 -->
<property name="format_sql">true</property><!-- 让输出的sql语句格式化 -->
</session-factory>
</hibernate-configuration>