正如你所問:「要打印帶這是Hibernate執行到日誌參數值的SQL查詢」
您可以設置以下參數到log4j.properties文件
#following parameters will be used to log the sql parameters
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type.descriptor.sql=trace
它將與sql參數一起打印查詢以及數據類型。
Hibernate: insert into employee (employee_address, employee_name, id) values (?, ?, ?)
11:50:40, 209 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [1] as [VARCHAR] - [Address 0]
11:50:40, 209 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [2] as [VARCHAR] - [Employee 0]
11:50:40, 209 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] - binding parameter [3] as [BIGINT] - [7008]
11:50:40, 210 DEBUG [org.hibernate.SQL] - insert into employee (employee_address, employee_name, id) values (?, ?, ?)
請訪問這個帖子有關代碼的詳細信息: - http://techpost360.blogspot.in/2016/10/hibernate-show-sql-with-parameter-values.html
甚至,如何可以打印帶有問號的這些SQL語句到我們預定義的日誌? – Pawan 2010-10-11 11:09:45