有图有真相,hibernate在console里显示sql语句的参数 有图有真相~~

用ssh2做课程设计时居然用hibernate添加不进数据库。因为看不到参数,hibernate打印的sql语句里是一大堆?,让我误以为是数据传输的问题。
Hibernate: select hibernate_sequence.nextval from dual
      Hibernate: insert into BBS_User (user_username, user_password, user_authority, user_id) values (?, ?, ?, ?)
于是乎,上网猛搜,力求在console里打印出完整的SQL语句。
这得从头说起,因为在网上找到的是log4j的配置方法,我也就不创新了(些许鄙视自己下。。。)先配log4j:
加入 log4j 的jar包。
WEB-INF下的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- utf8 start-->
<filter> <filter-name>SetCharacterEncoding</filter-name>
<filter-class>util.SetCharacterEncodingFilter</filter-class>
<init-param> <param-name>encoding</param-name>
<param-value>UTF-8</param-value> </init-param> </filter>
<filter-mapping> <filter-name>SetCharacterEncoding</filter-name>
<servlet-name>/*</servlet-name> </filter-mapping>
<!-- utf8 end-->
<!—index start-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!--index end-->
<!-- log4j的 start-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- log4j end -->
<!-- spring start-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext_hibernate.xml,
classpath:applicationContext_user.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- spring end-->
<!-- struts start-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- struts end-->
</web-app>
Tags:  猫扑有图有真相 有图有真相

延伸阅读

最新评论

发表评论