首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,073 阅读
2
类的加载
737 阅读
3
Spring Cloud OAuth2.0
725 阅读
4
SpringBoot自动装配原理
689 阅读
5
集合不安全问题
582 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
388
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
页面
统计
关于
搜索到
26
篇与
的结果
2021-10-23
Linux环境下安装MySQL
# 创建安装包文件夹,并下载mysql5.7.35安装包 mkdir -p /usr/local/database/ wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm # 安装 yum -y localinstall mysql57-community-release-el7-11.noarch.rpm yum -y install mysql-community-server # 设置开机自启 systemctl enable mysql # 将mysql数据目录从系统盘移动至数据盘 mkdir -p /data/mysql systemctl stop mysql cp -r /var/lib/mysql/* /data/mysql/ # 给新的mysql数据目录授权(必须执行) chown -R mysql:mysql mysql/ # 启动 systemctl start mysqld
2021年10月23日
227 阅读
0 评论
0 点赞
2020-12-14
动态SQL
动态SQL==根据不同的条件生成不同的SQL语句==ifchoose (when, otherwise)trim (where, set)foreach搭建环境CREATE TABLE `blog`( `id` VARCHAR(50) NOT NULL COMMENT 'id', `title` VARCHAR(100) NOT NULL COMMENT '标题', `author` VARCHAR(50) NOT NULL COMMENT '作者', `create_time` datetime NOT NULL COMMENT '创建时间', `views` int(11) NOT NULL COMMENT '浏览量' )ENGINE=INNODB DEFAULT CHARSET=utf8;1、导包2、编写配置文件3、创建实体类package com.sw.pojo; import lombok.Data; import java.io.Serializable; import java.util.Date; /** * @Author suaxi * @Date 2020/12/13 16:20 */ @Data public class blog implements Serializable { private String id; private String title; private String author; private Date createTime; private int views; } 4、编写实体类对应的Mapper接口和Mapper.xml文件IF<select id="findBlogIf" parameterType="map" resultType="Blog"> select * from blog where 1=1 <if test="title != null"> and title = #{title} </if> <if test="author != null"> and author = #{author} </if> </select>chose(when,otherwise)<select id="findBlogChoose" parameterType="map" resultType="Blog"> select * from blog <where> <choose> <when test="title != null"> title = #{title} </when> <when test="author != null"> and author = #{author} </when> <otherwise> and views = #{views} </otherwise> </choose> </where> </select>trim(where,set) <select id="findBlogIf" parameterType="map" resultType="Blog"> select * from blog <where> <if test="title != null"> title = #{title} </if> <if test="author != null"> and author = #{author} </if> </where> </select><update id="UpdateBlog" parameterType="map"> update blog <set> <if test="title != null"> title = #{title}, </if> <if test="author != null"> author = #{author} </if> </set> where id = #{id} </update>SQL片段将部分SQl抽取出来,方便复用1、使用SQL标签抽取公共部分<sql id="if-title-author"> <if test="title != null"> title = #{title} </if> <if test="author != null"> and author = #{author} </if> </sql>2、在需要使用的地方用include标签引用、<select id="findBlogIf" parameterType="map" resultType="Blog"> select * from blog <where> <include refid="if-title-author"></include> </where> </select>注:最好基于单表查询,不要存在where标签Foreach<!--select * from bolg where 1=1 and (id=1 or id=2 or id=3)--> <select id="findBlogForeach" parameterType="map" resultType="Blog"> select * from blog <where> <foreach collection="ids" item="id" open="and (" close=")" separator="or"> id = #{id} </foreach> </where> </select>==动态SQL就是在拼接SQL语句,先确保SQL的正确性,再按照SQL格式去排列组合==先在MySQL中写出完整的sql,再去修改成动态sql实现通用
2020年12月14日
99 阅读
0 评论
0 点赞
2020-11-09
SQL注入
SQL注入sql存在漏洞,会被攻击导致数据泄露,SQL会被拼接 orimport com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/9 9:57 */ public class SQlzhuru { public static void main(String[] args) { //login("sunxiaochuan","12345");正常登录 login(" 'or '1=1"," 'or '1=1"); //技巧 } //登录 public static void login(String username,String passwd){ Connection conn = null; Statement st = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 //SELECT * FROM users WHERE `name`='sunxiaochuan' AND `passwd`='12345'; //SELECT * FROM users WHERE `name`='' or '1=1' AND `passwd`='' or '1=1'; String sql = "SELECT * FROM users WHERE `name`='"+username+"' AND `passwd`='"+passwd+"'"; rs = st.executeQuery(sql); //查询完毕会返回一个结果集 while (rs.next()){ System.out.println(rs.getString("name")); System.out.println(rs.getString("passwd")); System.out.println("================="); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } }
2020年11月09日
71 阅读
0 评论
0 点赞
2020-11-09
PreparedStatement对象
可以防止SQL注入,效率更好。1、新增package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.util.Date; import java.sql.PreparedStatement; import java.sql.SQLException; /** * @Author suaxi * @Date 2020/11/9 10:12 */ public class TestInsert { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "insert into users(id,name,passwd,email,birthday) values(?,?,?,?,?)"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setInt(1,5); pstm.setString(2,"liubo"); pstm.setString(3,"12345"); pstm.setString(4,"liubo@qq.com"); //注:sql.Date 数据库使用 java.sql.Date() // util.Date Java new Date().getTime() 获得当前时间戳 pstm.setDate(5,new java.sql.Date(new Date().getTime())); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("插入成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 2、删除package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; /** * @Author suaxi * @Date 2020/11/9 10:28 */ public class TestDelete { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "delete from users where id=?"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setInt(1,5); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 3、修改package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; /** * @Author suaxi * @Date 2020/11/9 10:28 */ public class TestUpdate { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "update users set `name`=? where id=?"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setString(1,"孙笑川"); pstm.setInt(2,2); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("更新成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 4、查询package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * @Author suaxi * @Date 2020/11/9 10:34 */ public class TestSelect { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); String sql = "select * from users where id=?"; pstm = conn.prepareStatement(sql); //预编译 pstm.setInt(1,2); //传递参数 rs = pstm.executeQuery(); //执行 if (rs.next()){ System.out.println(rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,rs); } } } 5、防止SQL注入package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.*; /** * @Author suaxi * @Date 2020/11/9 9:57 */ public class SQlzhuru { public static void main(String[] args) { //login("dd","12345"); //正常登录 login("''or 1=1","12345"); } //登录 public static void login(String username,String passwd){ Connection conn = null; PreparedStatement pstm = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); //PreparedStatement防止SQL注入的本质,把传递进来的参数当作字符 //假设其中存在转义字符,例如 ' 会被直接转义 String sql = "select * from users where `name`=? and passwd=?"; pstm = conn.prepareStatement(sql); pstm.setString(1,username); pstm.setString(2,passwd); rs = pstm.executeQuery(); while (rs.next()){ System.out.println(rs.getString("name")); System.out.println(rs.getString("passwd")); System.out.println("================="); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,rs); } } }
2020年11月09日
103 阅读
0 评论
0 点赞
2020-11-08
statement对象
statement对象jdbc中的statement对象用于向数据库发送SQL语句,例如:想完成对数据库的增删查改,只需通过这个对象向数据库发送增删查改语句即可。Statement对象的executeUpdate方法,用于向数据库发送增、删、改的sql语句,executeUpdate执行完后,将会返回一个整数(即增删改语句导致了数据库几行数据发生了变化)。statement.executeQuery方法用于向数据库发送查询语句,executeQuery方法返回代表查询结果的resultSet对象。CRUD操作 --create使用executeUpdate(String sql)方法完成数据添加操作Statement st = conn.createStatement(); String sql = "insert into user(...) values(...)"; int num = st.executeUpdate(sql); if(num>0){ System.out.println("数据插入成功!"); }CRUD操作 --delete使用executeUpdate(String sql)方法完成数据删除操作Statement st = conn.createStatement(); String sql = "delete from user where id=1"; int num = st.executeUpdate(sql); if(num>0){ System.out.println("删除成功!"); }CRUD操作 --update使用executeUpdate(String sql)方法完成数据修改操作Statement st = conn.createStatement(); String sql = "update user set name='孙笑川' where id =1; int num = st.executeUpdate(sql); if(num>0){ System.out.println("修改成功!"); }CRUD操作 --read使用executeQuery(String sql)方法完成数据查询操作Statement st = conn.createStatement(); String sql = "select * from user; ResultSet rs = st.executeQuery(sql); while(re.next*()){ //根据获取列的数据类型,分别调用rs相应的方法映射到java对象中 }代码实现1、提取工具类package com.sw.kuangshen.utils; import java.io.InputStream; import java.sql.*; import java.util.Properties; /** * @Author suaxi * @Date 2020/11/8 21:06 */ public class JdbcUtils { private static String driver = null; private static String url = null; private static String username = null; private static String password = null; static{ try{ InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties"); Properties properties = new Properties(); properties.load(in); driver = properties.getProperty("driver"); url = properties.getProperty("url"); username = properties.getProperty("username"); password = properties.getProperty("password"); //1、驱动只用加载一次 Class.forName(driver); } catch (Exception e) { e.printStackTrace(); } } //获取连接 public static Connection getConnection() throws SQLException { return DriverManager.getConnection(url,username,password); } //释放资源 public static void release(Connection conn, Statement st, ResultSet rs){ if(rs!=null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(st!=null){ try { st.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn!=null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } 2、编写增删改的方法,都是用executeUpdate新增package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestInsert { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="INSERT INTO users(id,`name`,`passwd`,`email`,`birthday`)" + "VALUES(4,'dd','12345','dd@qq.com','1994-01-01')"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("插入成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 删除package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestDelete { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="DELETE FROM users WHERE id=1"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 修改package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestUpdate { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="UPDATE users SET `name`='sunxiaochuan' WHERE id=2"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("更新成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 3、查询 executeQuerypackage com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:45 */ public class TestSelect { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); st = conn.createStatement(); String sql = "select * from users where id=2"; rs = st.executeQuery(sql); //查询完毕会返回一个结果集 while (rs.next()){ System.out.println(rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } }
2020年11月08日
81 阅读
0 评论
0 点赞
2020-11-07
第一个JDBC程序
创建测试数据库CREATE DATABASE jdbcStudy CHARACTER SET utf8 COLLATE utf8_general_ci; USE jdbcStudy; CREATE TABLE users( id INT PRIMARY KEY, name VARCHAR(40), passwd VARCHAR(40), email VARCHAR(40), birthday DATE ); INSERT INTO users(id,name,passwd,email,birthday) VALUES(1,'aa','12345','aa@qq.com','1991-01-01'), (2,'bb','12345','bb@qq.com','1992-01-01'), (3,'cc','12345','cc@qq.com','1993-01-01');1、创建一个普通项目2、导入数据库驱动3、编写测试代码package com.sw.kuangshen; import java.sql.*; /** * @Author suaxi * @Date 2020/11/7 10:58 */ public class jdbcStudyDemo { public static void main(String[] args) throws ClassNotFoundException, SQLException { //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); //2.用户信息和url //useUnicode=true&characterEncoding=utf8&useSSL=true //支持中文编码 设置字符集为utf-8 使用安全的连接 String url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true"; String username = "root"; String password = "123456"; //3.连接成功,数据库对象 Connection connection = DriverManager.getConnection(url, username, password); //4.执行SQL的对象 Statement Statement statement = connection.createStatement(); //5.执行SQL的对象去执行SQL语句 String sql = "select * from users"; ResultSet resultSet = statement.executeQuery(sql); //返回的结果集,结果集里封装了查询出来的所有结果、 while (resultSet.next()){ System.out.println("id="+resultSet.getObject("id")); System.out.println("name="+resultSet.getObject("name")); System.out.println("pwd="+resultSet.getObject("passwd")); System.out.println("email="+resultSet.getObject("email")); System.out.println("birth="+resultSet.getObject("birthday")); System.out.println("========================="); } //6.释放连接(先开放的资源后释放) resultSet.close(); statement.close(); connection.close(); } } 步骤总结:1、加载驱动2、连接数据库DriverManager3、获取执行SQL的对象 Statement4、获得返回的结果集5、释放连接DriverManager//DriverManager.registerDriver(new com.mysql.jdbc.Driver()); Class.forName("com.mysql.jdbc.Driver"); //固定写法,加载驱动 Connection connection = DriverManager.getConnection(url, username, password); //connection 代表数据库 //数据库设置自动提交 //事务提交 //事务回滚 connection.rollback(); connection.commit(); connection.setAutoCommit();URLString url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true"; //mysql默认3306 //协议://主机地址:端口号/数据库名?参数1&参数2&参数3 //oracle默认1521 //jdbc:oracle:thin:@localhost:1521:sidStatement 执行SQL的对象 PrepareStatement执行SQL的对象String sql = "select * from users"; //编写SQL statement.executeQuery(); //查询操作返回resultSet statement.execute(); //执行任何SQL(其中包含一个判断是什么类型SQL的过程) statement.executeUpdate(); //更新、插入、删除都是用用这个,返回一个受影响的行数ResultSet 查询结果集:封装了所有的查询结果获得指定的数据类型resultSet.getObject(); //在不知道类型的情况下使用 //如果知道列的类型就使用指定的类型 resultSet.getString(); resultSet.getInt(); resultSet.getFloat(); resultSet.getDate(); ...遍历,指针resultSet.beforeFirst(); //移动到最前面 resultSet.afterLast(); //移动到最后面 resultSet.next(); //移动到下一个数据 resultSet.previous(); //移动到前一行 resultSet.absolute(row); //移动到指定行释放资源//释放连接(先开放的资源后释放) resultSet.close(); statement.close(); connection.close();
2020年11月07日
114 阅读
0 评论
0 点赞
2020-11-05
三大范式
三大范式为什么需要数据规范化?信息重复更新异常插入异常无法显示正常信息删除异常丢失有效的信息三大范式第一范式(1NF)原子性:保证每一列不可再分学号姓名学历信息1孙笑川本科,大一2刘波硕士,硕二3Giao哥博士,博三根据第一范式规范后为学号姓名学籍信息1孙笑川本科2刘波硕士3Giao哥博士姓名年级信息孙笑川大一刘波硕二Giao哥博三第二范式(2NF)前提:满足第一范式每张表只做一件事订单编号商品名单价数量订单金额时间001铅笔1.001010.0020201101002橡皮擦2.002040.0020201102003胶带3.003090.0020201103根据第二范式规范后为订单编号商品名单价数量001铅笔1.0010002橡皮擦2.0020003胶带3.0030订单编号订单金额时间00110.002020110100240.002020110200390.0020201103第三范式(3NF)前提:满足第一范式和第二范式第三范式需要确保数据表中的每一列数据都和主键直接关联,而不能间接相关学号学生姓名性别班主任班主任年龄001孙笑川男李明30002刘波男陈华31003Giao哥男刘丽32根据第三范式规范后为学号学生姓名性别班主任001孙笑川男李明002刘波男陈华003Giao哥男刘丽班主任班主任年龄李明30陈华31刘丽32规范性 与 性能的问题简要分析关联查询的表不得超过三张考虑商业化的需求和目标(成本,用户体验等),数据库的性能更加重要在规范性能问题的时候,需要适当的考虑一下规范性故意给某些表增加一些冗余字段(从多表查询变为单表查询)故意增加一些计算列(从大数据量降低为小数据量的查询:索引)
2020年11月05日
149 阅读
0 评论
0 点赞
2020-11-05
数据库设计规范
软件开发中,关于数据库的设计分析需求:分析业务和需要处理的数据库的需求概要设计:设计关系图 ,即E-R图设计数据库的步骤:(个人博客)收集信息,分析需求用户表(用户登录退出,个人信息,写博客,创建分类)分类表(文章分类,谁创建的)文章表(文章的信息)评论表友链表自定义表(系统信息,某个关键字,或者一些主字段) key:value*说说表(发表心情 id content create_time)标识实体(把需求具体到每个字段)标识实体之间的关系写博客:user-->blog创建分类:user-->category关注:user-->user友链:links评论:user-user-blog
2020年11月05日
103 阅读
0 评论
0 点赞
1
2
...
4