spring -jdbc增删改查

深藏阁楼爱情的钟 2022-03-17 06:38 407阅读 0赞
  1. package jdbc;
  2. import org.junit.Test;
  3. import org.junit.runner.RunWith;
  4. import org.springframework.jdbc.core.JdbcTemplate;
  5. import org.springframework.test.context.ContextConfiguration;
  6. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  7. import javax.annotation.Resource;
  8. @RunWith(SpringJUnit4ClassRunner.class)
  9. @ContextConfiguration("classpath:applicationContext.xml")
  10. public class jdbcTest {
  11. @Resource(name = "jdbcTemplate")
  12. private JdbcTemplate jdbcTemplate;
  13. @Test
  14. public void test2(){
  15. jdbcTemplate.update("insert into account values(null,?,?)" ,"张龙",10000);
  16. jdbcTemplate.update("delete from account where id =?" ,6);
  17. jdbcTemplate.update("update account set name= ?, mooney= ? where id = ?" ,"王3一",15000,8);
  18. String name = jdbcTemplate.queryForObject("select name from account where id = ? ",String.class,5);
  19. System.out.println(name);
  20. Long count = jdbcTemplate.queryForObject("select count(*) from account",Long.class);
  21. System.out.println(count);
  22. }
  23. }

发表评论

表情:
评论列表 (有 0 条评论,407人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JDBC增删案例讲解

    JDBC增删改查案例讲解 简介:这是一个网上非常常见的,JDBC的练习题,系统大家通过本文的讲解,熟悉JDBC的增删改查。 推荐学习路线:[JDBC数据库的连接][JD

    相关 JDBC进行增删

    JDBC进行增删改查 本篇博客较为基础,只作学习记录之用。 本篇分为: 下载JDBC的jar包 导入JDBC的jar包 封装数据库连接和关闭