Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载
首先,找齐Spring框架中IoC功能、aop功能、JdbcTemplate功能所需的jar包,当前13个Jar包
1、Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或注解生成对象
beans 、context、core 和expression
下载地址:
https://pan.baidu.com/s/1qXLHzAW
2、以及日志jar包,以便查看相关执行细节
commons-logging 和log4j
下载地址:
https://pan.baidu.com/s/1mimTW5i
3、再增加一个
spring-aop-5.0.1.RELEASE.jar (用于注解,在Spring-framework库中包含)
4、再增加
spring-aspects-5.0.1.RELEASE.jar (在Spring-framework库中包含)
aspectjweaver-1.8.12.jar (官方下载地址 http://mvnrepository.com/artifact/org.aspectj/aspectjweaver)
aopalliance-1.0.jar (官方下载地址 http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0)
实现aop功能,增强相关的切入点
5、JdbcTemplate功能所需Jar包
spring-jdbc-4.2.4.RELEASE.jar
spring-tx-4.2.4.RELEASE.jar
spring 框架jar包下载地址
链接: https://pan.baidu.com/s/1bpydNGV 密码: 2kvk
6、连接mysql数据库jar包
mysql-connector-java-5.1.7-bin.jar
下载地址:链接: https://pan.baidu.com/s/1geBRqqn 密码: 8jxm
应用Spring框架的JdbcTemplate方法删除数据库中数据
package com.swift; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Component; @Component(value="jdbcTemplateDemo")
public class JdbcTemplateDemo { public boolean delete(String username) {
DriverManagerDataSource dataSource=new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/sw_database");
dataSource.setUsername("root");
dataSource.setPassword("root"); JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
int count=jdbcTemplate.update("delete from sw_user where username=?", username);
if(count!=0) {
return true;
}
return false;
}
}
注解方法生成对象,所需xml配置文件代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 开启注解扫描——对象和属性 -->
<context:component-scan base-package="com.swift"></context:component-scan>
<!-- 开启aop注解方法 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> </beans>
调用JdbcTemplate删除数据库信息的Servlet类代码:
package com.swift; import java.io.IOException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; @WebServlet("/test")
public class ServletTest extends HttpServlet {
private static final long serialVersionUID = 1L; public ServletTest() {
super();
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
@SuppressWarnings("resource")
ApplicationContext context=new ClassPathXmlApplicationContext("aop.xml");
JdbcTemplateDemo jdbcTemplateDemo=(JdbcTemplateDemo) context.getBean("jdbcTemplateDemo");
if(jdbcTemplateDemo.delete("wangwu")) {
response.getWriter().append("delete success!");
}else {
response.getWriter().append("delete success!");
}
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }
Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载的更多相关文章
- Spring框架针对dao层的jdbcTemplate操作之jdbc数据库连接原始操作方法 所需安装包下载
crud指数据库或者持久层的基本操作,包括 增加(Create).读取查询(Retrieve 取回).更新(Update)和删除(Delete) Spring不仅对JDBC进行了封装,也对Hibern ...
- Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作
查询目标是完成3个功能: (1)查询表,返回某一个值.例如查询表中记录的条数,返回一个int类型数据 (2)查询表,返回结果为某一个对象. (3)查询表,返回结果为某一个泛型的list集合. 一.查询 ...
- Spring框架针对dao层的jdbcTemplate操作crud之update修改数据库操作
使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...
- Spring框架针对dao层的jdbcTemplate操作crud之add添加数据库操作
使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...
- Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作 —— 查询表,返回结果为对象的list集合
用JdbcTemplate的方法完成, 查询数据库表,把用户表sw_user所有数据以List<User>集合返回 在JdbcTemplateDemo类中增加查询返回所有对象集合的方法qu ...
- 解决Spring框架的Dao层改用@Repository注解,无法使用JdbcDaoSupport的问题
解决Spring框架的Dao层改用@Repository注解,无法使用JdbcDaoSupport的问题 Alternatively, create an own implementation of ...
- ssh整合思想 Spring与Hibernate的整合ssh整合相关JAR包下载 .MySQLDialect方言解决无法服务器启动自动update创建表问题
除之前的Spring相关包,还有structs2包外,还需要Hibernate的相关包 首先,Spring整合其他持久化层框架的JAR包 spring-orm-4.2.4.RELEASE.jar ( ...
- Spring、MyBatis和SpringMVC整合的jar包下载
spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...
- Spring配置连接池和 Dao 层使用 jdbcTemplate
1.Spring 配置 c3p0 连接池 (1)导入jar包(Maven项目) <dependency> <groupId>com.mchange</groupId> ...
随机推荐
- Spring Boot 创建自定义的properties文件
以IDEA2018为例,在资源文件夹上点击鼠标右键,依次选择 New -> Resource Bundle ,如下图: 在弹出的对话框中,填写properties文件的名称(不用填写.prope ...
- unity5之代码创建状态机,玩的666
http://blog.csdn.net/litaog00/article/details/50483189 最近做项目的时候用到了状态机,网上搜了一下帖子,大部分都是简单介绍使用方法的,讲解的详细的 ...
- 3d工具收集
Poser 是Metacreations公司推出的一款三维动物.人体造型和三维人体动画制作的极品软件.用过Poser 2与Poser 3的朋友一定能感受到Poser的人体设计和动画制作是那么的轻松自如 ...
- iOS图标去掉阴影和反光
在ios开发时, 程序的图标会被apple进行美化, 自动圆角, 加上阴影和反光效果: 如果有时候不想要阴影和反光,可以这样做: 在Info.plist中 添加一个Icon already inclu ...
- StringUtils.split()和string.split()的区别
场景 出于业务考虑,将多个字符串拼接起来时,使用的分隔符是;,;.如果要将这样一个拼接来的字符串分割成原本的多个字符串时,就需要使用到jdk自带的split()方法.不过因为公司的编程规范,改为使用了 ...
- Linux (二)
PS :显示系统进程 -a :显示所有进程(包括其他用户的进程) -u :用户以及其他详细信息 -x :显示没有控制终端的进程 -ef :显示所有 top :用于动态地监视进程活动与系统负载的信息 p ...
- 命令行媒体处理工具 FFmpeg
FFmpeg 是一套在命令行界面运行的跨平台媒体处理工具,属于自由软件,常用来对视频音频和图片等媒体文件进行格式转换.分割和合并等,也可录屏录音. 开发语言:C官网:https://www.ffmpe ...
- (转)MySql的常用的语句
MySQL常用语句 一.连接MySQL 格式: mysql -h 主机地址 -u 用户名 -p 用户密码 1.例1:连接到本机上的MYSQL. 首先在打开DOS窗口,然后进入目录 mysql bin, ...
- session是什么时候创建的
总结:session不是一打开网站就会立刻建立.它的建立需要基于下面两个条件中的任意一个: 1:在servlet中手动调用 HttpSession session = request.getSessi ...
- javaoo封装