❶ 添加配置了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>