Monday, May 23, 2011

log4jdbc: Una herramienta muy útil en desarrollo

Me estaba preguntando si existía una herramienta que permita ver los queries que se ejecutan contra la DB cuando se usa SimpleJdbcTemplate en Spring. Y.. existe. Se llama log4jdbc y la instalación es sencillisima.
Una vez instalado, en el log de la aplicación se podrán ver los queries y también el tiempo de ejecución.

(       45728) [http-8400-3         ] INFO  select DISTINCT location_code from PURCHASE_LINES where number = 'XXX'
                              | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:223) [2011-05-23 21:32:21,341]
(       46995) [http-8400-3         ] INFO  select DISTINCT codes from
PURCHASE_LINES where po_number = 'XXX'
 {executed in 1267 msec}      | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:322) [2011-05-23 21:32:22,608]
(       46997) [http-8400-3         ] INFO  5. ResultSet.new ResultSet returned                                                                                       | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,610]
(       46998) [http-8400-3         ] INFO  5. PreparedStatement.executeQuery() returned net.sf.log4jdbc.ResultSetSpy@159d796                                         | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,611]
(       46999) [http-8400-3         ] INFO  5. ResultSet.next() returned true                                                                                         | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,612]
(       47000) [http-8400-3         ] INFO  5. ResultSet.getMetaData() returned oracle.jdbc.driver.OracleResultSetMetaData@19e80b1                                    | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,613]
(       47001) [http-8400-3         ] INFO  5. ResultSet.getString(1) returned 10176 KKKKKK                                                                      | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,614]
(       47002) [http-8400-3         ] INFO  5. ResultSet.next() returned true                                                                                         | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,615]
(       47003) [http-8400-3         ] INFO  5. ResultSet.getMetaData() returned oracle.jdbc.driver.OracleResultSetMetaData@113126e                                    | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,616]
(       47004) [http-8400-3         ] INFO  5. ResultSet.getString(1) returned SSSSSSS                                                                           | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,617]
(       47005) [http-8400-3         ] INFO  5. ResultSet.next() returned true                                                                                         | at net.sf.log4jdbc.Slf4jSpyLogDelegator(Slf4jSpyLogDelegator.java:158) [2011-05-23 21:32:22,618]



Pretty cool, ah?

No comments:

Post a Comment