偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

讓Hibernate顯示SQL語句的綁定參數(shù)值

開發(fā) 后端
使用Hibernate提供的內(nèi)置屬性輸出SQL語句不利于程序的調試,為了可以顯示?占位符所代表的具體數(shù)據(jù),需要第三方Jar包,p6spy是一個該需求的開源實現(xiàn)。

使用Hibernate提供的內(nèi)置屬性<Property name="show_sql">true</Property>只能輸出類似于下面的SQL語句:

  1. Hibernate:   
  2.  
  3. insert into student(name, sex, age, cardId, classroom_id, id) values (?, ?, ?, ?, ?, ?) 

這樣不利于程序的調試,為了可以顯示?占位符所代表的具體數(shù)據(jù),需要第三方Jar包,p6spy是一個該需求的開源實現(xiàn)。

一、在Java Project項目中使用p6spy:

  1. 到其官方網(wǎng)站下載其Jar包,http://www.p6spy.com/(貌似不能訪問了)靠Google或Baidu搜索一下吧。
  2. 一般Download下來的是zip或jar文件包,將其解壓縮,將里面的p6spy.jar放入構建路徑里,將spy.properties文件放入src目 錄下。
  3. 修改兩個屬性,第一個,realdriver=你使用具體數(shù)據(jù)庫的驅動類(例如MySQL為:com.mysql.jdbc.Driver);第二個,logfile=指定log文件的位置(例如,c:/spy.log)。
  4. 修改Hibernate.cfg.xml配置文件中的 <property name="hibernate.connection.driver_class">com.p6spy.engine.spy.P6SpyDriver</property>

配置完畢后,執(zhí)行HQL語句后,查看spy.log文件就可以看到?占位符的具體數(shù)據(jù)了:(前面部分是Hibernate的初始化信息,最下面顯示的就是完整的SQL語句)

  1. 1326730516837|-1||debug||com.p6spy.engine.common.P6SpyOptions reloading properties  
  2. 1326730516842|-1||info||Using properties file: D:\WorkSpace\MyEclipse\9\hibernate\list mapping\bin\spy.properties  
  3. 1326730516842|-1||info||No value in environment for: getStackTrace, using: false  
  4. 1326730516842|-1||info||No value in environment for: getAppender, using: com.p6spy.engine.logging.appender.FileLogger  
  5. 1326730516842|-1||info||No value in environment for: getDeregisterDrivers, using: false  
  6. 1326730516842|-1||info||No value in environment for: getUsePrefix, using: false  
  7. 1326730516842|-1||info||No value in environment for: getExecutionThreshold, using: 0  
  8. 1326730516842|-1||info||No value in environment for: getAutoflush, using: true  
  9. 1326730516842|-1||info||No value in environment for: getExclude, using:   
  10. 1326730516842|-1||info||No value in environment for: getExcludecategories, using: info,debug,result,batch  
  11. 1326730516843|-1||info||No value in environment for: getFilter, using: false  
  12. 1326730516843|-1||info||No value in environment for: getInclude, using:   
  13. 1326730516843|-1||info||No value in environment for: getIncludecategories, using:   
  14. 1326730516843|-1||info||No value in environment for: getLogfile, using: spy.log  
  15. 1326730516843|-1||info||No value in environment for: getRealdriver, using: com.mysql.jdbc.Driver  
  16. 1326730516843|-1||info||No value in environment for: getRealdriver2, using:   
  17. 1326730516843|-1||info||No value in environment for: getRealdriver3, using:   
  18. 1326730516843|-1||info||No value in environment for: getAppend, using: true  
  19. 1326730516843|-1||info||No value in environment for: getSpydriver, using: com.p6spy.engine.spy.P6SpyDriver  
  20. 1326730516843|-1||info||No value in environment for: getDateformat, using:   
  21. 1326730516843|-1||info||No value in environment for: getDateformatter, using: null  
  22. 1326730516843|-1||info||No value in environment for: getStringmatcher, using: com.p6spy.engine.common.SubstringMatcher  
  23. 1326730516843|-1||info||No value in environment for: getStringMatcherEngine, using: com.p6spy.engine.common.SubstringMatcher@60e128  
  24. 1326730516843|-1||info||No value in environment for: getStackTraceClass, using:   
  25. 1326730516843|-1||info||No value in environment for: getSQLExpression, using: null  
  26. 1326730516843|-1||info||No value in environment for: getReloadProperties, using: false  
  27. 1326730516843|-1||info||No value in environment for: getReloadPropertiesInterval, using: 60  
  28. 1326730516843|-1||info||No value in environment for: getJNDIContextFactory, using: null  
  29. 1326730516843|-1||info||No value in environment for: getJNDIContextProviderURL, using: null  
  30. 1326730516844|-1||info||No value in environment for: getJNDIContextCustom, using: null  
  31. 1326730516844|-1||info||No value in environment for: getRealDataSource, using: null  
  32. 1326730516844|-1||info||No value in environment for: getRealDataSourceClass, using: null  
  33. 1326730516844|-1||info||No value in environment for: getRealDataSourceProperties, using: null  
  34. 1326730517419|7|0|statement|select max(id) from classroom|select max(id) from classroom  
  35. 1326730517440|0|0|statement|select max(id) from student|select max(id) from student  
  36. 1326730517454|0|0|statement|insert into classroom (grade, number, id) values (?, ?, ?)|insert into classroom (grade, number, id) values ('fourth grade', 1, 1)  
  37. 1326730517456|1|0|statement|insert into student (name, sex, age, cardId, classroom_id, id) values (?, ?, ?, ?, ?, ?)|insert into student (name, sex, age, cardId, classroom_id, id) values ('lisi', 'true', 21, '08053120', 1, 2)  
  38. 1326730517457|0|0|statement|update student set classroom_id=?, index_=? where id=?|update student set classroom_id=1index_=1 where id=2 
  39. 1326730517458|0|0|commit|| 

二、在Java Web項目中使用p6spy(Tomcat環(huán)境下)

  1. 將p6spy.jar 放入應用程序的WEB-INF/lib目錄,將spy.properties放入WEB-INF/classes目錄
  2. 其他與Java Project項目使用方法一樣。
  3. 重啟Tomcat服務器

可能會出現(xiàn)的問題:驅動程序加載先后的問題解決

如果spy.log里出現(xiàn)你的程序的數(shù)據(jù)庫驅動名稱 is a real driver in spy.properties, but it has been loaded before p6spy. p6spy will not wrap these connections. Either prevent the driver from loading, or try setting 'deregisterdrivers' to true in spy.properties.

請把spy.properties文件里的deregisterdrivers=false改為deregisterdrivers=true,重新運行即可。

原文鏈接:讓Hibernate顯示SQL語句的綁定參數(shù)值

【編輯推薦】

  1. Hibernate延遲加載剖析與代理模式應用
  2. 選用Ibatis和Hibernate的區(qū)別
  3. 如何在Hibernate中使用union
  4. Hibernate新項目誕生,謂之OGM
  5. Hibernate攔截器與監(jiān)聽器
責任編輯:林師授 來源: 音①曉的博客
相關推薦

2010-03-31 15:03:54

Oracle執(zhí)行

2009-09-25 15:03:21

Hibernate綁定

2019-10-22 13:34:06

SQL數(shù)據(jù)庫語句解讀

2010-04-01 14:14:56

Oracle綁定變量

2009-09-24 18:11:56

Hibernate q

2011-03-17 13:54:42

查詢參數(shù)SQL語句利用率

2010-09-07 14:50:15

SQL語句

2010-09-07 10:42:12

SQL語句

2013-05-24 10:22:07

Python默認參數(shù)值

2009-09-24 10:35:10

Hibernate查詢

2009-07-21 16:17:28

iBATIS.NET

2011-03-04 15:20:09

vsFTPDIP

2009-06-25 16:45:31

Hibernate

2015-08-26 16:26:19

SQL

2023-11-10 18:03:04

業(yè)務場景SQL

2010-11-08 17:01:53

SQL Server綁

2023-03-30 09:10:06

SQLSELECTFROM

2010-09-03 15:47:40

SQL語句鎖定

2010-09-03 14:39:15

SQLSELECT語句

2010-11-08 16:56:52

SQL Server綁
點贊
收藏

51CTO技術棧公眾號