In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to effectively track Bug records with detailed parameter values of SQL, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
In the actual development work, may need a lot of debugging work, through debugging, may be able to better find the specific problems of the program.
Imagine, today, QA colleagues reported you a bug, of course, they will not give a specific reason, but only give the results caused by Bug, then how do you fix this bug, obviously everyone's way of dealing with the problem is different, but it will be like this: ask QA, why there is such a Bug ah, when and where … ? After that, you may pretend to be thinking and say a long time later, this is not our problem, it is the deployment problem, it is the DB problem. Of course, you can also chat (generally speaking, QA is MM ^ _ ^).
Of course, this is not what good and passionate programmers do (maybe you are, but it doesn't matter, maybe everyone is doing the same thing more or less all the time). Ideally, based on QA MM's description, plus finding useful logs, can reproduce and solve Bug, and if possible, talk to MM about how this Bug is caused.
In most environments, we use very popular frameworks, such as Hibernate. When you check the log, of course you will care about the SQL records in it, but these SQL may not be of practical value because it loses a lot of useful information. First of all, you should know that if you are concerned about the SQL generated by Hibernate, of course you need to turn on the Show Sql function (), but you will find that after you turn it on, the Log record is an insert like this.
... ??? Statement, of course, this is of some practical value, but these statements can only be regarded as the shelf of SQL, not a complete SQL that can be run, and do have more detailed data, such as "?" here. What is it.
If you care about the question mark in SQL (? ) what is it, then please read the following? If you think you didn't pay attention to this during debugging, you can move to find what you are really interested in, and of course you are welcome to continue reading.
This article introduces these two protagonists: log4jdbc and jdbcdslog. With reference to the official documentation (which is detailed and comprehensive), you should be able to configure these Tools foolishly. Here I will give some suggestions on how to use them and improve and enhance the functionality of these tools.
Log4jdbc home page
Http://code.google.com/p/log4jdbc/
Sample configuration
Mysql.database.driver=net.sf.log4jdbc.DriverSpy
Mysql.database.url=jdbc:log4jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8
(for the configuration of other log and dependent packages, please refer to the official website)
Use evaluation
The advantage of log4jdbc is that it is easy to configure, supports all mainstream databases, and there is a native sql in log (can be run directly, this idea is also the reason why I want to transform jdbcdslog, described below), and the whole project code is written beautifully, but unfortunately, DataSource (XA,Pooling) is not supported yet, because of this I abandoned it, and now the project is DataSource + XA, which really feels a bit of a pity. However, if you download the source code, you will know that there is a TODO that the author will implement in the next version, hoping that the log4jdbc extension will become more and more practical. There is an article http://code.google.com/p/log4jdbc/wiki/DataSourceExampleForWebSphere on the official website wiki, which also describes how to use DataSource.
I have not studied it in depth. If you are interested, you can study it and open source it again. Accordingly, you will thank you for your hard work.
There is indeed a Javaer implementation on Google code (google code projcect url:
Log4jdbc-remix), I used it and found that there was a problem on the basis of not changing the original configuration (log4jdbc). For the wrong specific issues, please see http://code.google.com/p/log4jdbc-remix/issues/detail?id=3, which was not used later (although I believe the author must have shared it after a successful transformation, which may be caused by some environmental problems).
(I believe you can successfully configure the relevant configuration through the official website. If you have any questions, you can refer to a small Demo that I use log4jdbc. Please use svn check.
Http://usc.googlecode.com/svn/SSHWithAnnotationDemoUselog4jdbc/).
Jdbcdslog home page
Http://code.google.com/p/jdbcdslog/
Sample configuration
MySql
Mysql.database.driver=org.jdbcdslog.DriverLoggingProxy
Mysql.database.url=jdbc\: jdbcdslog\: mysql\: / / 127.0.0.1\: 3306/test?useUnicode\ = true&characterEncoding\ = utf-8;targetDriver\ = com.mysql.jdbc.Driver
Mysql.database.user=root
Mysql.database.password=lishunli
Mysql.database.maxActive=100
Mysql.database.maxIdle=30
Mysql.database.maxWait=500
Spring DI
(for the use of jndi, please google)
Weblogic + Oracle
Jdbc:oracle:thin:@10.100.53.85:1521:cmn?targetDS=oracle.jdbc.xa.client.OracleXADataSource
Org.jdbcdslog.ConnectionPoolXADataSourceProxy
User
Mssapp
ServerName
10.100.53.85
PortNumber
1521
SID
Cmn
{3DES} ThgsfHr3yB1bfpnD4u/t3A==
JBoss + Oracle
Jdbc/coreDataSource
True
True
True
False
Org.jdbcdslog.ConnectionPoolXADataSourceProxy
Jdbc:oracle:thin:@10.100.53.85:1521:cmn?targetDS=oracle.jdbc.xa.client.OracleXADataSource
Report
Report
ten
two hundred
Org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
Use evaluation
Support for DataSource (XA,Pooling) is the biggest highlight of jdbcdslog, and another is that the author is really attentive, wiki (document) is so detailed that as long as you see this wiki, you can use jdbcdslog;, and the unfriendly sql recorded by log is its biggest drawback (I personally think so, and you think it's perfect). If you can display the complete SQL like log4jdbc, then jdbcdslog is excellent.
In order to move towards my own perfect goal, I enhanced jdbcdslog to meet my (and perhaps others) needs.
Note: personally, I feel unfriendly: although the parameters are clearly written, this statement cannot be used directly (run the sql directly on the console). If necessary, you may need to replace one of our parameters before you can use it.
(for related configuration, please refer to a small Demo that I use jdbcdslog. Please use svn check.
Http://usc.googlecode.com/svn/SSHWithAnnotationDemo/).
Jdbcdslog-exp home page
Of course, this is my fork, the home page is in http://code.google.com/p/jdbcdslog-exp/, specific enhancements and how to use, can be found here.
Sample configuration
This will not be posted, because jdbcdslog-exp does not modify the configuration of jdbcdslog, just use its configuration. However, enhancements will require a little configuration, which will be discussed below.
Effect.
Compare the enhanced effect with the effect above, and you will see what I have modified (pay attention to the red underline)
Have you found that the sql can be run directly, and the log of execution time is removed (copying is simpler, Sql is generally very long, and you can select a line from "select" to shift+end). Is it very convenient?
New features and how to use
1) you can directly fill in the parameters of the SQL statement. Of course, the generated log statement can be copied and used directly, which is already reflected in the above effect image.
The generated SQL varies from database to database, such as keywords (special characters), such as' and & and\ r,\ n,\ tSQL Server'in Oracle.
There are 'and "and\ and\ r,\ n,\ t in Mysql (Note: special characters in the like statement have been considered, but jdbcdslog-exp has not been implemented. In this part, I think the usage is relatively low, and if there is one, it should not be so difficult to pay attention to.), such as the date format. So how to change the database type to select the appropriate generation statement, please see:
Configure it in the jdbcdslog.properties file (you can refer to the original documentation, or simply create a new jdbcdslog.properties configuration file and put it under the class path path).
# jdbcdslog driver name.if empty,is oracle (default db)
# you may choose "oracle", "mysql", "sqlserver" or empty (Case-insensitive and does not need the double quotes)
Jdbcdslog.driverName=oracle
2) you can configure whether or not to display the execution time of SQL, which is not shown by default. This default choice is also reflected in the above effect image. Of course, you can show it through the configuration below.
Also configured in the jdbcdslog.properties file
# jdbcdslog will show elapsed time
Jdbcdslog.showTime=true
3) Maven support
The world of Maven has come or is coming. Of course, you should support it. You can rely on it like this:
Com.googlecode.usc
Jdbcdslog
1.0.6.2
Jdbcdslog-exp has been placed in the central warehouse of Maven (how to deploy to maven central repo? Please read my last article: Maven
For the sake of name consistency, jdbcdslog is chosen as the build name instead of jdbcdslog-exp for how Artifacts is deployed to the repository.
Or http://jdbcdslog-exp.googlecode.com/files/jdbcdslog-1.0.6.2.jar by downloading it and putting it into class
Patch is fine. For more downloads, please see http://code.google.com/p/jdbcdslog-exp/downloads/list, including source code and Javadoc. Of course, you can go down through svn checkout and continue to improve yourself. Svn url is
Http://jdbcdslog-exp.googlecode.com/svn/trunk/ .
In fact, this blog post has been written a long time ago, but it has been delayed by the following questions:
I use Weblogic + Oracle (installed on other local machines) and org.jdbcdslog.ConnectionPoolXADataSourceProxy, but somehow, in some cases, weblogs will get stuck and cannot be executed, and after a period of time, there will be a Time Out exception. After a long time of debugging and checking, there may be two reasons:
1) Bug of jdbcdslog (jdbcdslog-exp) itself, there is no corresponding closed link for handling datasource types (I guess)
2) there is a problem with the local Oracle DB installation, because this has happened to my colleagues, but much less than me.
But you don't have to worry, this situation is relatively rare and does not affect normal use (development phase). If you know why this happens or there are similar problems, you are welcome to discuss. Thank you.
Summary or suggestion
1. If you want to use jdbcdslog or jdbcdslog-exp, please read jdbcdslog's UserGuide first
Http://code.google.com/p/jdbcdslog/wiki/UserGuide .
2.jdbcdslog is just a stand-alone package that requires support from slf4j-api and slf4j-log4j12.
In 3.Log, you only need to turn on the info of statement, and you don't need anything else. When considering performance testing, it's a different matter. Like (log4j.xml):
The above implementation of the JDBC tool uses proxies, similar to AOP ideas, to get the data information brought by JDBC by listening (or better to say Spy) the data layer. Of course, there are many excellent toolkits that can do this, such as spy6.
The above is how to effectively track Bug records of SQL with detailed parameter values. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.