栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring +JDBC配置与使用(含增删查改)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring +JDBC配置与使用(含增删查改)

Spring +JDBC配置与使用

文章目录
  • Spring +JDBC配置与使用
    • 添加Spring依赖
    • 添加mysql依赖
    • 创建person类
    • 创建dao包
    • 创建数据库表
    • 测试方法
    • 删、查、改

mysql安装可以参考这篇文章

新建spring项目(含导入spring依赖)
Spring第一讲—Spring入门案例

添加Spring依赖

 org.springframework
 spring-core
 5.3.8


 org.springframework
 spring-beans
 5.3.8


 org.springframework
 spring-context
 5.3.8


 org.springframework
 spring-context-support
 5.2.12.RELEASE


 org.springframework
 spring-expression
 5.3.8


 commons-logging
 commons-logging
 1.2


添加mysql依赖


      mysql
      mysql-connector-java
      8.0.20
    
    
      org.springframework
      spring-jdbc
      5.3.8
    
    
      org.springframework
      spring-tx
      5.3.8
    

    
      org.springframework
      spring-aop
      5.3.8
    

spring容器中创建DriverManagerDataSource和JdbcTemplate对象

    
        
        
        
        
        
        
        
        

    

    
        

    
创建person类

快速生成get和set方法:
右键---->generate---->Getter and Setter---->按住Shift后全选----->OK

创建dao包

创建数据库表

测试方法

ApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");

        PersonDao personDao = (PersonDao) applicationContext.getBean("personDao");
        personDao.addPerson("text123",20);

查看数据库表(需要刷新)

增加数据就成功了

删、查、改


测试

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/287372.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号