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>