`

spring servlet jdbc

阅读更多

这个文章的关注点是如何在只准使用servlet jsp jdbc的情况下 加入spring来简化 jdbc代码 事务控制 依赖注入

 

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">
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<filter>
		<filter-name>WebFilter</filter-name>
		<filter-class>
			org.springframework.web.filter.DelegatingFilterProxy
		</filter-class>
		<init-param>
			<param-name>targetFilterLifecycle</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>WebFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml
		</param-value>
	</context-param>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
</web-app>

 applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
	- Application context definition for JPetStore's business layer.
	- Contains bean references to the transaction manager and to the DAOs in
	- dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
-->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
	<bean id="WebFilter" class="test.spring.WebFilter">
		<property name="manageSupport" ref="manageSupport" />
	</bean>

	<bean id="manageSupport" class="test.spring.ManageSupport">
		<property name="name" value="bingo" />
		<property name="jdbcTemplate" ref="jdbcTemplate"></property>
	</bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
    <constructor-arg>
        <ref bean="dataSource"/>
    </constructor-arg>
    </bean>

	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
		<property name="url" value="jdbc:jtds:sqlserver://127.0.0.1:1433/xxx" />
		<property name="username" value="sa" />
		<property name="password" value="sa" />
	</bean>
</beans>

 

WebFilter.java

package test.spring;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class WebFilter implements Filter {

    private ManageSupport manageSupport;

    public void destroy() {
        // TODO Auto-generated method stub

    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
        System.out.println(getClass().getName() + " filter");
        System.out.println(manageSupport.getName());
        int count = manageSupport.getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM MESSAGE");
        System.out.println(count);
        arg2.doFilter(arg0, arg1);
        HttpServletRequest req = (HttpServletRequest) arg0;
        req.getSession().getServletContext().getRequestDispatcher("/index2.jsp").forward(arg0, arg1);

    }

    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub

    }

    public ManageSupport getManageSupport() {
        return manageSupport;
    }

    public void setManageSupport(ManageSupport manageSupport) {
        this.manageSupport = manageSupport;
    }

}

 

ManageSupport.java

package test.spring;

import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class ManageSupport{
    
    private SimpleJdbcTemplate jdbcTemplate;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SimpleJdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(SimpleJdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
}

 事物控制在spring的sample里有参考

 

研究了一下事物

改动如下

打算针对ManageSupport做自动事物切入

把ManageSupport重构出接口 用eclipse可以在几秒实现这个

package test.spring;

import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public interface IManageSupport {

    public abstract String getName();

    public abstract void setName(String name);

    public abstract SimpleJdbcTemplate getJdbcTemplate();

    public abstract void setJdbcTemplate(SimpleJdbcTemplate jdbcTemplate);
    public int logic1();
    public void logic2();
}

 

在实现中的事物逻辑

public int logic1(){
        return getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM JB_COM_MESSAGE");
    }
    
    public void logic2(){
        int count=logic1();
        for (int i = 1; i <= count; i++) {
            getJdbcTemplate().update("update JB_COM_MESSAGE set m_level =1 where id=?", i);
        }
    }

 调用业务方法的方法  WebFilter.java中的

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
        System.out.println(getClass().getName() + " filter");
        System.out.println(manageSupport.getName());
        int count = manageSupport.logic1();
        System.out.println(count);
        manageSupport.logic2();
        arg2.doFilter(arg0, arg1);
        HttpServletRequest req = (HttpServletRequest) arg0;
        req.getSession().getServletContext().getRequestDispatcher("/index2.jsp").forward(arg0, arg1);
    }

 

spring配置中 事务相关

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
  <property name="url" value="jdbc:jtds:sqlserver://127.0.0.1:1433/DSO" />
  <property name="username" value="sa" />
  <property name="password" value="sa" />
 </bean>

 <aop:config>
  <aop:advisor pointcut="execution(* test.spring.IManageSupport.*(..))" advice-ref="txAdvice" />
 </aop:config>
 
 <tx:advice id="txAdvice">
  <tx:attributes>
   <tx:method name="logic*" propagation="REQUIRED" />
  </tx:attributes>
 </tx:advice>

 

最后执行成功 以下是log

test.spring.WebFilter filter
[DEBUG] 2009-12-07 10:26:45 [http-8080-Processor25] [org.springframework.transaction.interceptor.TransactionInterceptor.prepareTransactionInfo:300]  Don't need to create transaction for [test.spring.IManageSupport.getName]: This method isn't transactional.
bingo
[DEBUG] 2009-12-07 10:26:45 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.getTransaction:371]  Creating new transaction with name [test.spring.IManageSupport.logic1]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[DEBUG] 2009-12-07 10:26:45 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202]  Acquired Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] for JDBC transaction
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219]  Switching JDBC Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] to manual commit
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.bindResource:186]  Bound value [org.springframework.jdbc.datasource.ConnectionHolder@6f0962] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.initSynchronization:261]  Initializing transaction synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.interceptor.TransactionInterceptor.prepareTransactionInfo:290]  Getting transaction for [test.spring.IManageSupport.logic1]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.query:436]  Executing SQL query [SELECT COUNT(*) FROM JB_COM_MESSAGE]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@6f0962] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@6f0962] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@6f0962] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.interceptor.TransactionInterceptor.commitTransactionAfterReturning:319]  Completing transaction for [test.spring.IManageSupport.logic1]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerBeforeCommit:903]  Triggering beforeCommit synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerBeforeCompletion:916]  Triggering beforeCompletion synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.processCommit:730]  Initiating transaction commit
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259]  Committing JDBC transaction on Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerAfterCommit:929]  Triggering afterCommit synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerAfterCompletion:945]  Triggering afterCompletion synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.clearSynchronization:315]  Clearing transaction synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.doUnbindResource:232]  Removed value [org.springframework.jdbc.datasource.ConnectionHolder@6f0962] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] from thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314]  Releasing JDBC Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] after transaction
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection:312]  Returning JDBC Connection to DataSource
6
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.getTransaction:371]  Creating new transaction with name [test.spring.IManageSupport.logic2]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202]  Acquired Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] for JDBC transaction
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219]  Switching JDBC Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] to manual commit
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.bindResource:186]  Bound value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.initSynchronization:261]  Initializing transaction synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.interceptor.TransactionInterceptor.prepareTransactionInfo:290]  Getting transaction for [test.spring.IManageSupport.logic2]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.query:436]  Executing SQL query [SELECT COUNT(*) FROM JB_COM_MESSAGE]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [2], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [3], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [4], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [5], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.update:790]  Executing prepared SQL update
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.execute:574]  Executing prepared SQL statement [update JB_COM_MESSAGE set m_level =1 where id=?]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal:207]  Setting SQL statement parameter value: column index 1, parameter value [6], value class [java.lang.Integer], SQL type unknown
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement:800]  SQL update affected 1 rows
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.getResource:142]  Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] bound to thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.interceptor.TransactionInterceptor.commitTransactionAfterReturning:319]  Completing transaction for [test.spring.IManageSupport.logic2]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerBeforeCommit:903]  Triggering beforeCommit synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerBeforeCompletion:916]  Triggering beforeCompletion synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.processCommit:730]  Initiating transaction commit
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259]  Committing JDBC transaction on Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerAfterCommit:929]  Triggering afterCommit synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.triggerAfterCompletion:945]  Triggering afterCompletion synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.clearSynchronization:315]  Clearing transaction synchronization
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.transaction.support.TransactionSynchronizationManager.doUnbindResource:232]  Removed value [org.springframework.jdbc.datasource.ConnectionHolder@139a0dc] for key [org.apache.commons.dbcp.BasicDataSource@17e9134] from thread [http-8080-Processor25]
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314]  Releasing JDBC Connection [jdbc:jtds:sqlserver://127.0.0.1:1433/DSO, UserName=sa, jTDS Type 4 JDBC Driver for MS SQL Server and Sybase] after transaction
[DEBUG] 2009-12-07 10:26:46 [http-8080-Processor25] [org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection:312]  Returning JDBC Connection to DataSource

 

 

分享到:
评论
1 楼 mootools215 2010-09-02  
无用信息太多,文章只显示关键代码就好,完整的可提供下载

相关推荐

    java 教程包含(hibernate struts Spring Servlet JDBC 基础)

    Java教程涵盖了广泛的Web开发技术,包括Hibernate、Struts、Spring、Servlet和JDBC,以及JSP中的图片验证。这些技术都是构建高效、可扩展的企业级应用程序的基础。让我们逐一深入探讨这些知识点。 1. **JDBC(Java ...

    java开发之SpringMVC + Spring + SpringJDBC整合.zip

    2. 配置Spring:在servlet-context.xml中配置Spring的核心组件,包括Bean工厂、AOP、数据源以及JDBC模板。 3. 集成SpringJDBC:配置数据源,创建JdbcTemplate实例,然后在Service层中使用它进行数据库操作。 4. ...

    Spring mvc、 Spring、 Spring jdbc 整合实例源码

    1. **配置文件**:包括Spring的主配置文件(如`applicationContext.xml`),其中定义了Bean的配置,包括DataSource、JdbcTemplate或JpaTemplate等,以及Spring MVC的配置文件(如`servlet-context.xml`),定义了...

    Spring+Spring MVC+Spring JDBC+MySql实现简单登录注册

    5. **配置文件**:项目中的配置文件(可能在`config`目录下)包括Spring的bean配置文件(如`applicationContext.xml`)和Spring MVC的配置文件(如`servlet-context.xml`)。这些文件定义了Bean的实例化、依赖关系...

    Spring mvc + Spring + Spring jdbc 整合 demo

    1. **配置文件**:项目通常包含两个主要的配置文件,一个用于Spring MVC(如servlet-context.xml),另一个用于Spring框架的核心配置(如applicationContext.xml)。这些文件会定义Bean,包括Controller、Service、...

    经典bbs源码(struts+spring+jdbc)

    7. **控制层(Controller)**:Struts的ActionServlet和Spring的DispatcherServlet负责请求的分发,以及处理用户的输入。 通过研究这个源码,开发者可以了解如何在实际项目中运用Struts的MVC架构,Spring的依赖注入...

    spring4 、 springmvc4.2、springjdbc

    3. 配置Spring MVC:创建Spring MVC的配置文件,如`servlet-context.xml`,配置DispatcherServlet、视图解析器、模型-视图映射等。 4. 编写业务逻辑:创建控制器、服务和DAO层的类,使用Spring的注解如@Controller、...

    mvc servlet jdbc web框架

    理解Servlet和JDBC可以帮助开发者更好地掌握Spring Boot、Spring MVC或Hibernate等高级框架。而MVC模式则是理解和设计任何Web应用结构的基础。 在实际开发中,虽然直接使用Servlet和JDBC的方式比较原始且工作量较大...

    maven-springMVC-springJDBC-Demo

    3. **src/main/resources**: 存放配置文件,如Spring的bean配置文件(如`applicationContext.xml`或`dispatcher-servlet.xml`)。 4. **src/main/webapp**: Web应用程序的根目录,包含静态资源(如HTML、CSS、...

    jsp+servlet+jdbc+mysql项目

    【标题】"jsp+servlet+jdbc+mysql项目"是一个典型的Web开发实践,它结合了四种核心技术,用于构建基于Java的动态网页应用。JSP(JavaServer Pages)是用于创建动态网页的服务器端技术,它允许开发者在HTML代码中嵌入...

    Java Servlet+JDBC的增删改查

    Java Servlet+JDBC的增删改查是Java Web开发中的基础操作,主要涉及数据库交互以及服务器端处理。在这个过程中,IntelliJ IDEA作为强大的集成开发环境(IDE)扮演着核心角色,提供了一个高效的编程环境。下面我们将...

    struts2,spring,jdbc整合所需jar包

    Struts2、Spring和JDBC是Java开发中常用的三大框架,它们在企业级应用开发中起着关键作用。Struts2作为一个成熟的MVC框架,负责处理HTTP请求并映射到相应的业务逻辑;Spring则是一个全面的后端解决方案,提供依赖...

    spring 与 servlet整合

    5. **数据访问集成**:Spring支持多种数据访问技术,包括JDBC、Hibernate、MyBatis等,提供统一的API进行数据操作。 **Servlet的角色** 1. **HTTP服务器端接口**:Servlet是Java EE平台中用于接收和处理HTTP请求的...

    struts1+spring2.5.6+jdbc配置

    Struts1、Spring 2.5.6 和 JDBC 是经典的Java Web开发技术组合,它们各自在应用程序架构中扮演着不同的角色。Struts1是MVC(Model-View-Controller)框架,Spring则是一个全面的轻量级应用框架,而JDBC(Java ...

    servlet与spring整合例子

    Spring提供了对各种持久化技术(如JDBC、Hibernate、MyBatis等)的集成,使得在Servlet中操作数据库变得简单。我们可以在Spring配置文件中定义数据源和DAO Bean,然后在Servlet中通过依赖注入获取这些DAO对象,执行...

    spring+servlet所用jar

    4. **JDBC驱动JAR**:如果你的Spring应用需要数据库操作,你需要对应数据库的JDBC驱动,如mysql-connector-java.jar(对于MySQL)。 5. **其他依赖JAR**:如commons-logging.jar、log4j.jar等日志处理库,以及可能...

    【基础练习】jsp+servlet+jdbc 网上购物商系统(带sql脚本)

    往后学习,大家会碰到很多的框架,例如JDBC的配置类不需要自己写,用mybatis就可以做连接和增删改查,例如servlet也会被spring boot的注解所代替,但是归根结底,它们都是要基于这类知识的。我会把我 拓展了的地方写...

    Java Servlet 实现登录

    在Java Web开发中,Servlet扮演着核心角色,特别是在处理用户交互和业务逻辑方面。本示例将详细介绍如何使用Java Servlet实现一个基本的登录功能。 首先,我们需要创建一个Servlet类,它是Java类,继承自...

Global site tag (gtag.js) - Google Analytics