logging SQL expressions from within HSQLDB

可紊 提交于 2019-11-30 04:56:31

问题


I use HSQLDB in my application. Now i need to log every single sql statement which was executed. I do not want to handle SQL-logging myself. Is there a standart way of doing this from within HSQLDB?


回答1:


HSQLDB 2.2.x supports SQL logging. Suppose your database is named test and you connect using the JDBC URL jdbc:hsqldb:file:test

  1. test.log is the data change log used internally by HSQLDB. It does not contain SELECT statements. It is created and deleted by HSQLDB. This is not what you are looking for.

  2. test.sql.log is the log that contains all the SQL statements with time and session info, together with any arguments for prepared statements. This log is created if you use:

    SET DATABASE EVENT LOG SQL LEVEL 3

It contains entries such as these:

2012-02-08 22:19:36.484 DETAIL 4 CALL USER() 
2012-02-08 22:19:36.484 DETAIL 4 call database_version() 
2012-02-08 22:19:36.484 DETAIL 4 COMMIT 
2012-02-08 22:19:36.500 DETAIL 4 INSERT INTO Customer VALUES(0,'Laura','Steel','429 Seventh Av.','Dallas') 

You can use the hsqldb.sqllog=3 on the URL

  1. test.sql.app.log is the log that contains entries for internal persistence operations. This is not related to the executed SQL statements.

See the Guide here and check the command and property syntax at the end of the chapter:

http://hsqldb.org/doc/2.0/guide/management-chapt.html#mtc_monitoring_operation




回答2:


Not HSQLDB specific, but if your client is using JDBC perhaps easiest way to log SQL statements is to use JDBC driver wrapper. There are plenty implementations to choose from.



来源:https://stackoverflow.com/questions/9192815/logging-sql-expressions-from-within-hsqldb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!