當前位置:首頁 » 編程語言 » log4jhibernatesql
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

log4jhibernatesql

發布時間: 2022-02-25 01:54:53

❶ 添加配置了Slf4J和log4j的配置文件logback.xml,增加了 <prop key="hibernate.use_sql_comments">

logback。xml不是log4j的配置文件。log4j.properties

❷ 如何設置hibernate列印sql語句

只要加上下面這個語句就可以了 Log4j.propreties代碼 #輸出sql語句到日誌 log4j.logger.org.hibernate.SQL=debug #將對應的參數佔位符?換成傳入的參數 log4j.logger.org.hibernate.type=trace

❸ 如何得到hibernate顯示在控制台的hql或sql語句

不知道樓主的意思是不是把那些佔位符換成具體的值,這樣就可以直接復制SQL語句在資料庫控制台粘貼直行了。

如果是這樣的話。樓主有沒有注意過直行hibernate時總是報的警告:
log4j:WARN Please initialize the log4j system properly.
使用這個log4j就可以顯示相信信息。

我給你一個屬性文件:log4j.properties把他放到和hibernate.cfg.xml相同目錄下。修改屬性文件中屬性log4j.logger.org.hibernate.type=debug
這樣,就可以顯示詳細數據了。

把以下內容保存命名log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'error' ###

log4j.rootLogger=warn, stdout

#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=error

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=error

### log just the SQL
#log4j.logger.org.hibernate.SQL=error

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug
#log4j.logger.org.hibernate.type=error

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=error

### log HQL parse trees
#log4j.logger.org.hibernate.hql=error

### log cache activity ###
#log4j.logger.org.hibernate.cache=error

### log transaction activity
#log4j.logger.org.hibernate.transaction=error

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=error

### enable the following line if you want to track down connection ###
### leakages when using ###
#log4j.logger.org.hibernate.connection.=trace

❹ 怎麼樣配置log4j 才能將hibernate在控制台輸出sql語句

因為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語句。

❺ hibernate log4j 在console處輸出信息時不換行

建議 抄別人的配置,參考參考

hibernate.cfg.xml 配置文件中添加以下三條配置,就可以在控制台顯示執行的sql:

<!-- 是否顯示sql -->
<property name="show_sql">true</property>
<!-- 是否格式化sql -->
<property name="format_sql">true</property>
<!-- 是否使用注釋 -->
<property name="use_sql_comments">true</property>

❻ 請問為什麼我這里log4j.logger.org.hibernate.tool.hbm2ddl如果等於error

在你hibernate的配置文件裡面加上
<property name="show_sql">false</property>

❼ 如何將Hibernate生成的SQL語句列印到日誌文件

1 操作
只需要在log4j.properties中加入以下兩行代碼即可
#輸出sql語句到日誌
log4j.logger.org.hibernate.SQL=debug

#將對應的參數佔位符?換成傳入的參數
log4j.logger.org.hibernate.type=trace

實驗效果:

2017-09-05 16:51:26 [DubboServerHandler-thread-1] DEBUG org.hibernate.SQL (104) -
select
cpsysparm0_.CODE as CODE65_0_,
cpsysparm0_.NAME as NAME65_0_,
cpsysparm0_.PARMVALUE as PARMVALUE65_0_,
cpsysparm0_.PARMDESC as PARMDESC65_0_,
cpsysparm0_.MODIFIABLE as MODIFIABLE65_0_,
cpsysparm0_.VIEWABLE as VIEWABLE65_0_,
cpsysparm0_.OPERUSER as OPERUSER65_0_,
cpsysparm0_.OPERTIME as OPERTIME65_0_
from
CP_SYSPARM cpsysparm0_
where
cpsysparm0_.CODE=?
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder (83) - binding parameter [1] as [VARCHAR] - 012
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [當前場次 ] as column [NAME65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [1] as column [PARMVALUE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (67) - Found [null] as column [PARMDESC65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [0] as column [MODIFIABLE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [1] as column [VIEWABLE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [init ] as column [OPERUSER65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [2011-11-23 10:06:47.0] as column [OPERTIME65_0_]

可以看到查詢的過程和結果都進行了輸出。

❽ SSH 添加 log4j 後,在action中執行 log.debug("aaaaa")沒反應,但是在main方法中執行,有輸出

這個你參照下面的,修改輸出的內容等級就可以了

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
#log4j.rootLogger=debug, warn, stdout
log4j.rootCategory=WARN, stdout
#log4j.category.org.springframework.beans.factory=DEBUG
#log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug
### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug
### log just the SQL
#log4j.logger.org.hibernate.SQL=debug
### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug
### log schema export/update ###
#log4j.logger.org.hibernate.tool.hbm2ddl=debug
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
### log cache activity ###
#log4j.logger.org.hibernate.cache=debug
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
### enable the following line if you want to track down connection ###
### leakages when using ###
#log4j.logger.org.hibernate.connection.=trace

❾ hibernate 使用log4j在myeclipse中輸出SQL完整信息,但是怎麼弄都沒顯示,大家看看那裡錯了

hibernate在控制台顯示sql代碼,是在property節點添加如下內容<property name="show_sql">true</property>,配置了這個應該就可以顯示sql語句。你的錯誤,很有可能是配置的前面的錯誤,影響了後面的運行。或者你寫的代碼根本就沒有實現從資料庫提取數據的功能。

❿ log4j.xml 如何在控制台列印jdbc執行過的sql

問題要描述清楚,使用什麼框架,是hibernate,還是mybatis,或者自己寫的資料庫連接工具。如果是hibernate,需要在hibernate屬性文件中配置hibernate.show_sql=true,或者在hibernate.cfg.xml文件中配置。
如果是mybatis,配置log4j
<category name="org.apache.ibatis" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="console"/>
</category>