In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Use the log framework in Jfinal to output complete sql statement information (mysql+oracle)
1. Introduce Jar package.
/ / jar packages that must be introduced
Log4j-1.2.17.jar
Log4jdbc4-1.2.jar
Slf4j-api-1.7.5.jar
/ / choose one of the jar packages. If you have already introduced either of them in your project, you don't need to introduce the other one. Introducing the above two packages at the same time will cause stack overflow. For more information, please see this document:
Http://blog.csdn.net/kxcfzyk/article/details/38613861
Slf4j-log4j12-1.7.5.jar
Or
Log4j-over-slf4j-1.7.7.jar
2. Modify database configuration information
-mysql
JdbcUrl = jdbc:log4jdbc:mysql://127.0.0.1/mxtt?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
User = root
Password = root123
# devMode = true
# log4jdbc
DriverClass=net.sf.log4jdbc.DriverSpy
-oracle--
JdbcUrl = jdbc:log4jdbc:oracle:thin:@127.0.0.1:1521:ORC
User = scott
Password = tiger
# devMode = true
# log4jdbc
DriverClass=net.sf.log4jdbc.DriverSpy
3. Modify jfinal core configuration class
-mysql--
Private static Prop p = PropKit.use ("config.properties"); / / load configuration file
Public static DruidPlugincreateDruidPlugin () {
DruidPlugin dp = new DruidPlugin (p.get ("jdbcUrl"), p.get ("user"), p.get ("password") .trim ()
Dp.setDriverClass (p.get ("driverClass"))
Dp.addFilter (new StatFilter ())
Dp.addFilter (new Slf4jLogFilter ())
WallFilter wall = new WallFilter ()
Wall.setDbType (JdbcUtils.MYSQL)
Dp.addFilter (wall)
Returndp
}
Public void configPlugin (Plugins me) {
/ / configure the C3p0 database connection pool plug-in
DruidPlugindruidPlugin = createDruidPlugin ()
Me.add (druidPlugin)
/ / configure the ActiveRecord plug-in
ActiveRecordPluginarp = new ActiveRecordPlugin (druidPlugin)
StringbaseSqlTemplatePath = PathKit.getWebRootPath () + "/ WEB-INF/sql"
Arp.setBaseSqlTemplatePath (baseSqlTemplatePath)
File [] files = new File (baseSqlTemplatePath) .listFiles
For (File f: files) {
If (f.isFile () & & f.getName () .endsWith (".SQL")) {
Arp.addSqlTemplate (f.getName ())
}
}
/ / if (p.getBoolean ("devMode", false)) {
/ / arp.setShowSql (true)
/ /}
/ / all mappings are automatically done in MappingKit
_ MappingKit.mapping (arp)
Me.add (arp)
}
-oracle--
Private static Prop p = PropKit.use ("config.properties"); / / load configuration file
Public static DruidPlugincreateDruidPlugin () {
DruidPlugin dp = new DruidPlugin (p.get ("jdbcUrl"), p.get ("user"), p.get ("password") .trim ()
Dp.setDriverClass (p.get ("driverClass"))
Dp.setValidationQuery ("select 1 from dual")
Dp.addFilter (new StatFilter ())
Dp.addFilter (new Slf4jLogFilter ())
WallFilter wall = new WallFilter ()
Wall.setDbType (JdbcUtils.ORACLE)
Dp.addFilter (wall)
Returndp
}
Public void configPlugin (Plugins me) {
/ / configure the Druid database connection pool plug-in
DruidPlugindruidPlugin = createDruidPlugin ()
Me.add (druidPlugin)
/ / configure the ActiveRecord plug-in
ActiveRecordPluginarp = new ActiveRecordPlugin (druidPlugin)
StringbaseSqlTemplatePath = PathKit.getWebRootPath () + "/ WEB-INF/sql"
Arp.setBaseSqlTemplatePath (baseSqlTemplatePath)
File [] files = new File (baseSqlTemplatePath) .listFiles
For (File f: files) {
If (f.isFile () & & f.getName () .endsWith (".SQL")) {
Arp.addSqlTemplate (f.getName ())
}
}
/ / if (p.getBoolean ("devMode", false)) {
/ / arp.setShowSql (true)
/ /}
/ / configure Oracle dialect
Arp.setDialect (new OracleDialect ())
/ * set the transaction run level. Oracle database only supports READCOMMITTED and SERIALIZABLE.
TRANSACTION_NONE= 0; / / JDBC driver does not support transactions
TRANSACTION_READ_UNCOMMITTED= 1; / / allows dirty, unrepeatable and phantom reading.
TRANSACTION_READ_COMMITTED= 2; / / prohibits dirty reading, but allows unrepeatable and phantom reading.
TRANSACTION_REPEATABLE_READ= 4; / / prohibit dirty reading and non-repeatable reading, and run phantom reading alone.
TRANSACTION_SERIALIZABLE = 8; / / dirty reading, non-repeatable reading and phantom reading are prohibited.
, /
Arp.setTransactionLevel (2)
/ / configure property name (field name) case-insensitive container factory is true field name all lowercase
Arp.setContainerFactory (new CaseInsensitiveContainerFactory (true))
Me.add (arp)
/ / all configurations other than the relevant tables of the permission system are automatically generated by _ JFinalGenerator in _ MappingKit
_ MappingKit.mapping (arp)
}
4. Modify log output configuration file (log4j.properties)
# log4j.rootLogger=WARN, stdout, file
Log4j.rootLogger=ERROR, stdout, file
Log4j.appender.stdout=org.apache.log4j.ConsoleAppender
Log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
Log4j.appender.stdout.layout.ConversionPattern=%n%-d {yyyy-MM-ddHH:mm:ss}% n [% p]-[Thread:% t]-[% C.% M ()]:% m% n
# Output to the File
Log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
Log4j.appender.file.DatePattern='_'yyyy-MM-dd'.log'
Log4j.appender.file.File=./mxtt.cc.log
Log4j.appender.file.layout=org.apache.log4j.PatternLayout
Log4j.appender.file.layout.ConversionPattern=%n%-d {yyyy-MM-ddHH:mm:ss}% n [% p]-[Thread:% t]-[% C.% M ()]:% m% n
# output sql statement and execution time
Log4j.logger.jdbc.sqltiming=INFO,console
# output only sql statements
# log4j.logger.jdbc.sqlonly=DEBUG,console
# log4j.logger.jdbc.connection=INFO,console
# log4j.appender.console=org.apache.log4j.ConsoleAppender
# log4j.appender.console.layout=org.apache.log4j.PatternLayout
# log4j.appender.console.layout.ConversionPattern=%d {yyyy-MM-ddHH:mm:ss.SSS}% m%n%n
Finally, the download address of the jar package is attached: http://pan.baidu.com/s/1pLyl0Wb
Http://www.mxtt.cc http://www.51fenxiang.xyz
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.