spring -jdbc增删改查

package jdbc;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class jdbcTest {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;
    @Test
    public  void  test2(){
        jdbcTemplate.update("insert into account values(null,?,?)" ,"张龙",10000);
      jdbcTemplate.update("delete from account where id =?" ,6);
      jdbcTemplate.update("update  account set name= ?, mooney= ? where id = ?" ,"王3一",15000,8);

                String name = jdbcTemplate.queryForObject("select name from account where id = ? ",String.class,5);
                System.out.println(name);

                Long count = jdbcTemplate.queryForObject("select count(*) from account",Long.class);
                System.out.println(count);

    }
    
    
}

猜你喜欢

转载自blog.csdn.net/dagedeshu/article/details/87883684