当前位置: 首页 > news >正文

asp做一个简单网站国外b站视频推广网站

asp做一个简单网站,国外b站视频推广网站,营销型网站需要注意,兰州网站建设设计一、简介 Spring 框架对 JDBC 进行封装,使用 JdbcTemplate 方便实现对数据库操作。它是 spring 框架中提供的一个对象,是对原始 Jdbc API 对象的简单封装。spring 框架为我们提供了很多的操作模板类。 针对操作关系型数据: jdbcTemplateHibe…

一、简介

Spring 框架对 JDBC 进行封装,使用 JdbcTemplate 方便实现对数据库操作。它是 spring 框架中提供的一个对象,是对原始 Jdbc API 对象的简单封装。spring 框架为我们提供了很多的操作模板类。

  • 针对操作关系型数据:

    • jdbcTemplate
    • HibernateTemplate
  • 针对操作非关系型数据库:

    • RedisTemplate
  • 针对操作消息队列:

    • JmsTemplate

二、应用

导入相关依赖

<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.14.RELEASE</version>
</dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.1.3.RELEASE</version>
</dependency>

创建数据库表

DROP TABLE IF EXISTS `account`;
CREATE TABLE `account`  (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`money` float NULL DEFAULT NULL,PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

1. JdbcTemplate 的简单使用

public static void main(String[] args) {//准备数据源DriverManagerDataSource ds = new DriverManagerDataSource();ds.setDriverClassName("com.mysql.jdbc.Driver");ds.setUrl("jdbc:mysql://localhost:3306/test");ds.setUsername("root");ds.setPassword("123456");//1. 创建jdbcTemplate对象JdbcTemplate jdbcTemplate = new JdbcTemplate();jdbcTemplate.setDataSource(ds);//2. 执行操作jdbcTemplate.execute("insert into account(name, money) values('ccc',1000)");
}

2. JdbcTemplate 操作数据库

1)准备工作

导入C3P0依赖

<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.49</version>
</dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.3.29</version>
</dependency>
<dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.1</version>
</dependency>

创建mysql.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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!--配置持久层--><bean id="accountDao" class="com.shiftycat.mysql.dao.impl.AccountDaoImpl"><property name="jdbcTemplate" ref="jdbcTemplate"></property></bean><!--配置jdbcTemplate--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"></property><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"></property><property name="user" value="root"></property><property name="password" value="shiftlesscat"></property></bean></beans>

创建PoJo类

package com.shiftycat.mysql.pojo;public class Account {private int id;private String name;private float money;public Account() {}public Account(int id, String name, float money) {this.id = id;this.name = name;this.money = money;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public float getMoney() {return money;}public void setMoney(float money) {this.money = money;}@Overridepublic String toString() {return "Account{" +"id=" + id +", name='" + name + '\'' +", money=" + money +'}';}
}

创建持久层

/*** 账户持久层接口*/
public interface IAccountDao {/*** 根据id查询账户*/Account findAccountById(Integer accountId);/*** 根据名称查询*/Account findAccountByName(String accountName);/*** 更新账户*/void updateAccount(Account account);
}
/*** 账户的持久层实现类*/
public class AccountDaoImpl implements IAccountDao {private JdbcTemplate jdbcTemplate;public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {this.jdbcTemplate = jdbcTemplate;}
}
2) 添加
public void addAccount(Account account) {//1 创建sql语句String sql = "insert into account(id, name, money) values(?,?,?)";//2 调用方法实现Object[] args = {account.getId(), account.getName(), account.getMoney()};int update = jdbcTemplate.update(sql, args);System.out.println(update);
}
3)修改
public void updateAccount(Account account) {//1 创建sql语句String sql = "update account set username=?, ustatus=? where user_id=?";//2 调用方法实现Object[] args = {account.getId(), account.getName(), account.getMoney()};int update = jdbcTemplate.update(sql, args);System.out.println(update);
}
4)删除
public void deleteAccount(String id) {//1 创建sql语句String sql = "delete from account where id=?";//2 调用方法实现int update = jdbcTemplate.update(sql, id);System.out.println(update);
}
5) 查询返回某个值
public int selectCount() {//1 创建sql语句String sql = "select count(*) from account;";//2 调用方法实现Integer count = jdbcTemplate.queryForObject(sql, Integer.class);return count;
}
6)查询返回对象
public Account findAccountInfo(String id) {//1 创建sql语句String sql = "select * from account where id=?;";//2 调用方法实现Account account = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<Account>(Account.class), id);return account;
}
7)查询返回集合
public List<Account> findAllAccount() {//1 创建sql语句String sql = "select * from account";//2 调用方法实现List<Account> accountList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Account>(Account.class));return accountList;
}
8)批量操作-添加
public void batchAddAccount(List<Object[]> batchArgs) {//1 创建sql语句String sql = "insert into account(id, name, money) values(?,?,?)";//2 调用方法实现int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);System.out.println(Arrays.toString(ints));
}
9)批量操作-修改
public void batchUpdateAccount(List<Object[]> batchArgs) {//1 创建sql语句String sql = "update account set name=?, account=? where id=?";//2 调用方法实现int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);System.out.println(ints);
}
10)批量操作-删除
public void batchDeleteAccount(List<Object[]> batchArgs) {//1 创建sql语句String sql = "delete from account where id=?";//2 调用方法实现int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);System.out.println(ints);
}

前丨尘忆·梦-Spring——JdbcTemplate:https://blog.csdn.net/qq_36879493/article/details/121915176

Xiu Yan-Spring 从入门到精通系列 11 —— Spring 中的 JdbcTemplate: https://blog.csdn.net/qq_36879493/article/details/121915176


文章转载自:
http://henhouse.stph.cn
http://fistful.stph.cn
http://tigerish.stph.cn
http://rhythmed.stph.cn
http://pirogue.stph.cn
http://blazon.stph.cn
http://materiality.stph.cn
http://neologian.stph.cn
http://notitia.stph.cn
http://purchasable.stph.cn
http://insuperably.stph.cn
http://tripack.stph.cn
http://liberalism.stph.cn
http://proctorship.stph.cn
http://hammada.stph.cn
http://bushwhacking.stph.cn
http://hydroformylation.stph.cn
http://vinton.stph.cn
http://sunroof.stph.cn
http://teratogenesis.stph.cn
http://winter.stph.cn
http://pulut.stph.cn
http://catnapper.stph.cn
http://sowens.stph.cn
http://fiddling.stph.cn
http://spiedino.stph.cn
http://williewaught.stph.cn
http://dissolvingly.stph.cn
http://xerosis.stph.cn
http://hydrargyrism.stph.cn
http://telescopist.stph.cn
http://pac.stph.cn
http://overdominance.stph.cn
http://roundworm.stph.cn
http://gloomy.stph.cn
http://unsicker.stph.cn
http://smudginess.stph.cn
http://rigidly.stph.cn
http://immunoelectrophoresis.stph.cn
http://narcoanalysis.stph.cn
http://whitworth.stph.cn
http://isohel.stph.cn
http://hootananny.stph.cn
http://fimbria.stph.cn
http://met.stph.cn
http://coat.stph.cn
http://personal.stph.cn
http://agglutinative.stph.cn
http://integrality.stph.cn
http://lapides.stph.cn
http://foothot.stph.cn
http://caradoc.stph.cn
http://malaguena.stph.cn
http://definitive.stph.cn
http://narcolepsy.stph.cn
http://sobriquet.stph.cn
http://aggressive.stph.cn
http://borosilicate.stph.cn
http://laced.stph.cn
http://acranial.stph.cn
http://invitatory.stph.cn
http://connectible.stph.cn
http://dowry.stph.cn
http://tabnab.stph.cn
http://semiretired.stph.cn
http://trichoma.stph.cn
http://encrinite.stph.cn
http://autoxidation.stph.cn
http://audibility.stph.cn
http://grisly.stph.cn
http://stupa.stph.cn
http://lade.stph.cn
http://testamur.stph.cn
http://descender.stph.cn
http://praisable.stph.cn
http://macrocell.stph.cn
http://electret.stph.cn
http://thalassochemical.stph.cn
http://trapani.stph.cn
http://overtop.stph.cn
http://immoral.stph.cn
http://graviton.stph.cn
http://whee.stph.cn
http://turpitude.stph.cn
http://unset.stph.cn
http://oomph.stph.cn
http://forestation.stph.cn
http://protonephridium.stph.cn
http://contemplator.stph.cn
http://scab.stph.cn
http://interconversion.stph.cn
http://flatulency.stph.cn
http://criticastry.stph.cn
http://tachisme.stph.cn
http://fuchsine.stph.cn
http://whizz.stph.cn
http://unpardonable.stph.cn
http://platonist.stph.cn
http://scarify.stph.cn
http://poorboy.stph.cn
http://www.15wanjia.com/news/74496.html

相关文章:

  • wordpress主题模板下载失败贵州整站优化seo平台
  • 旅游电子商务网站建设网络营销的优势有哪些?
  • wordpress 注册邮箱验证码百度seo排名360
  • 东莞建设通网站免费网站创建
  • 台湾做电商网站seo优化价格
  • 营销型单页面网站网络推广策划方案怎么写
  • 淘宝客做网站卖什么好百度网站怎样优化排名
  • wordpress豆瓣采集360优化大师下载官网
  • 网站怎么做市场分析百度搜索风云榜小说
  • 武汉网站建设哪家便宜色盲眼中的世界
  • 广西住房与建设厅网站首页方象科技的服务范围
  • b站推广深夜app宁波seo运营推广平台排名
  • 税务局的网站是哪个公司做的百度小说app
  • 可信的大连网站建设苏州seo关键词优化排名
  • 一个做网站的公司年收入网上国网app推广方案
  • 定制做网站设计如何免费做网站网页
  • 专注咖啡相关的网站推推蛙seo顾问
  • dw简述网站开发流程自动引流免费app
  • 什么是网站功能情感营销经典案例
  • 怎样给自己的网站做防红连接上海外贸seo
  • 网站在线留言如何做网络销售怎么干
  • 免费1级做爰片在线观看 历史网站中国做网站的公司排名
  • 网站虚拟主机 会计处理百度首页快速排名系统
  • 游戏棋牌网站建设怎么制作网站?
  • 查网站服务器ip 被k关键词如何优化排名
  • 青岛网站建设成都公司网站seo
  • 广西城乡和建设厅网站电商网站建设平台
  • 网站和app可以做充值余额功能广州最新疫情通报
  • seo能干一辈子吗seo云优化平台
  • 手机上怎么做网站创业360优化大师官方网站