<repo_name>iamleohanstudy/han<file_sep>/src/test/java/han/handatatest.java
package han;
import han.repository.JdbcRepository;
import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:testdata-config.xml")
@Transactional
public class handatatest extends TestCase {
	
	@Autowired
	private JdbcRepository jdbcRepository;
	
	
	
	//test
	@Test
	public void testData1(){
		
		
		String sqlchange ="update t_account set name ='leohan' where number = 123456789";
		
		jdbcRepository.updateData(sqlchange);
		
		String sql1 = "select name from t_account where number = 123456789";
		
		String result = jdbcRepository.getData(sql1);
		
		
		assertEquals("leohan", result);
		
	}
	
	
	

	@Test
	public void testData2(){
		
		String sql1 = "select name from t_account where number = 123456789";
		
		String result = jdbcRepository.getData(sql1);
		
		assertEquals("Keith and <NAME>", result);
	}
	
	

}
<file_sep>/src/main/java/han/repository/JdbcRepository.java
package han.repository;

public interface JdbcRepository {
	public String getData(String sql);
	
	
	public void updateData(String sql);
}
<file_sep>/src/main/java/han/repository/JdbcRepositoryImpl.java
package han.repository;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;



@Repository
public class JdbcRepositoryImpl implements JdbcRepository {
	
	private DataSource dataSource;
	
	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	JdbcRepositoryImpl(DataSource dataSource){
		this.dataSource = dataSource;
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	@SuppressWarnings("deprecation")
	@Override
	public String getData(String sql) {
		
		String result = jdbcTemplate.queryForObject(sql, String.class);
		
		System.out.println("query result is :"+result);
		
		return result;
		
	}

	@Override
	public void updateData(String sql) {
		// TODO Auto-generated method stub
		
		jdbcTemplate.update(sql);
		
	}
	
}
<file_sep>/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>leo</groupId>
	<artifactId>han</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>han</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>hsqldb</groupId>
			<artifactId>hsqldb</artifactId>
			<version>1.8.0.10</version>
		</dependency>


	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<showDeprecation>true</showDeprecation>
					<showWarnings>true</showWarnings>
					<executable>${env.JAVA_HOME_7}/bin/javac</executable>
					<fork>true</fork>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
