首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,082 阅读
2
类的加载
741 阅读
3
Spring Cloud OAuth2.0
726 阅读
4
SpringBoot自动装配原理
691 阅读
5
集合不安全问题
584 阅读
笔记
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
页面
统计
关于
搜索到
46
篇与
的结果
2021-01-02
Redis基本数据类型Zset
Zset在set的基础上增加了一个值set key value zset key score value127.0.0.1:6379> zadd myzset 1 A #添加一个值 (integer) 1 127.0.0.1:6379> zadd myzset 2 B 3 C #添加多个值 (integer) 2 127.0.0.1:6379> zrange myzset 0 -1 1) "A" 2) "B" 3) "C" 127.0.0.1:6379> #排序 127.0.0.1:6379> zadd grade 100 sun (integer) 1 127.0.0.1:6379> zadd grade 80 liubo (integer) 1 127.0.0.1:6379> zadd grade 66 giao (integer) 1 127.0.0.1:6379> zrangebyscore grade -inf +inf #显示全部的学生(升序) 1) "giao" 2) "liubo" 3) "sun" 127.0.0.1:6379> zrevrange grade 0 -1 #降序排列 1) "sun" 2) "giao" 127.0.0.1:6379> 127.0.0.1:6379> zrangebyscore grade -inf +inf withscores #显示全部的学生并附带分数(升序) 1) "giao" 2) "66" 3) "liubo" 4) "80" 5) "sun" 6) "100" 127.0.0.1:6379> zrangebyscore grade -inf 90 withscores #显示成绩小于90的学生(升序) 1) "giao" 2) "66" 3) "liubo" 4) "80" 127.0.0.1:6379> # zrem 移除元素 127.0.0.1:6379> zrange grade 0 -1 1) "giao" 2) "liubo" 3) "sun" 127.0.0.1:6379> zrem grade liubo (integer) 1 127.0.0.1:6379> zrange grade 0 -1 1) "giao" 2) "sun" # zcard 获取有序集合中的个数 127.0.0.1:6379> zcard grade (integer) 2 127.0.0.1:6379> # zcount 获取指定区间的数量 127.0.0.1:6379> zcount grade 1 2 Zset可用于成绩表、工资表排序、网站排行榜等方面
2021年01月02日
71 阅读
0 评论
0 点赞
2021-01-02
Redis基本数据类型Set
Set(集合)set中的值不能重读,与list操作一样,set操作以s开头127.0.0.1:6379> sadd set hello #添加值 (integer) 1 127.0.0.1:6379> sadd set world (integer) 1 127.0.0.1:6379> smembers set #查看指定set的所有值 1) "hello" 2) "world" 127.0.0.1:6379> sismember set hello #判断某一个值是否存在set集合中 (integer) 1 127.0.0.1:6379> scard set #获取set集合中内容元素的个数 (integer) 2 127.0.0.1:6379> # srem 移除元素 127.0.0.1:6379> smembers set #移除set集合中的指定元素 1) "hello1" 2) "hello2" 3) "hello" 4) "hello3" 127.0.0.1:6379> srem set hello (integer) 1 127.0.0.1:6379> smembers set 1) "hello1" 2) "hello2" 3) "hello3" 127.0.0.1:6379> # srandmember 随机抽取元素 127.0.0.1:6379> srandmember set #随机抽取一个元素 "hello1" 127.0.0.1:6379> srandmember set "hello2" 127.0.0.1:6379> srandmember set 2 #随机抽取指定个数的元素 1) "hello1" 2) "hello2" 127.0.0.1:6379> srandmember set 2 1) "hello" 2) "hello3" 127.0.0.1:6379> # spop 随机移除set集合中的元素 127.0.0.1:6379> spop set "hello3" 127.0.0.1:6379> spop set "hello" 127.0.0.1:6379> # smove 移动指定元素到其他set集合中 127.0.0.1:6379> sadd set01 hello (integer) 1 127.0.0.1:6379> sadd set01 bihao (integer) 1 127.0.0.1:6379> sadd set01 xiexie (integer) 1 127.0.0.1:6379> sadd set02 chouxiang (integer) 1 127.0.0.1:6379> smove set01 set02 xiexie (integer) 1 127.0.0.1:6379> smembers set01 1) "hello" 2) "bihao" 127.0.0.1:6379> smembers set02 1) "chouxiang" 2) "xiexie" 127.0.0.1:6379> # 差集 交集 并集 127.0.0.1:6379> smembers set01 1) "a" 2) "d" 3) "b" 4) "c" 5) "e" 127.0.0.1:6379> smembers set02 1) "b" 2) "c" 127.0.0.1:6379> sdiff set01 set02 #差集 1) "e" 2) "a" 3) "d" 127.0.0.1:6379> sinter set02 set02 #交集 1) "b" 2) "c" 127.0.0.1:6379> sunion set01 set02 #并集 1) "c" 2) "e" 3) "b" 4) "a" 5) "d" 具体应用如:共同关注,二度好友,(推荐好友,可能认识的人)六度分割理论
2021年01月02日
53 阅读
0 评论
0 点赞
2021-01-02
Redis基本数据类型Hash
Hashkey-value键值对key-map===>此时将value换成了一个map集合hash的本质与String没有太大的区别127.0.0.1:6379> hset hash field nihao #set一个具体的key-value (integer) 1 127.0.0.1:6379> hget hash field "nihao" 127.0.0.1:6379> hmset myhash field01 nihao filed02 xiexie #set多个key-value OK 127.0.0.1:6379> hmget myhash field01 filed02 #获取多个字段值 1) "nihao" 2) "xiexie" 127.0.0.1:6379> hgetall myhash #获取全部的数据 1) "field01" 2) "nihao" 3) "filed02" 4) "xiexie" 127.0.0.1:6379> # hdel 删除hash指定key字段,key对应的value值也同时被删除 127.0.0.1:6379> hdel myhash filed02 (integer) 1 127.0.0.1:6379> hgetall myhash 1) "field01" 2) "nihao" 127.0.0.1:6379> # hlen 获取hash表的字段数量 127.0.0.1:6379> hgetall myhash 1) "field01" 2) "nihao" 3) "field02" 4) "xiexie" 127.0.0.1:6379> hlen myhash (integer) 2 # hexists 判断hash中指定字段是否存在 127.0.0.1:6379> hgetall myhash 1) "field01" 2) "nihao" 3) "field02" 4) "xiexie" 127.0.0.1:6379> hexists myhash field01 (integer) 1 127.0.0.1:6379> 127.0.0.1:6379> hkeys myhash #只获取所有的field字段 1) "field01" 2) "field02" 127.0.0.1:6379> hvals myhash #只获取所有的value值 1) "nihao" 2) "xiexie" 127.0.0.1:6379> 127.0.0.1:6379> hset myhash field03 2 (integer) 1 127.0.0.1:6379> hincrby myhash field03 1 #设置自增 (integer) 3 127.0.0.1:6379> hsetnx myhash field04 ceshi #如果不存在则创建 (integer) 1 127.0.0.1:6379> hsetnx myhash field04 ceshi01 #如果存在则不能创建 (integer) 0 hash更适合对象的存储(如:用户信息变更,经常改动的数据等),String更适合字符串的存储。
2021年01月02日
99 阅读
0 评论
0 点赞
2021-01-02
Redis基本数据类型List
List(列表)所有的List命令都是以l开头的#插入 127.0.0.1:6379> lpush list a #将一个或多个值插入到列表头部 (integer) 1 127.0.0.1:6379> lpush list b (integer) 2 127.0.0.1:6379> lpush list c (integer) 3 127.0.0.1:6379> lrange list 0 -1 #range [key] 0 -1获取全部的值 1) "c" #后进先出(栈) 2) "b" 3) "a" 127.0.0.1:6379> lrange list 0 1 1) "c" 2) "b" 127.0.0.1:6379> rpush list d #rpush从头部插入 (integer) 4 127.0.0.1:6379> lrange list 0 -1 1) "c" 2) "b" 3) "a" 4) "d" 127.0.0.1:6379> #移除 127.0.0.1:6379> lrange list 0 -1 1) "c" 2) "b" 3) "a" 4) "d" 127.0.0.1:6379> lpop list #移除第一个元素 "c" 127.0.0.1:6379> lrange list 0 -1 1) "b" 2) "a" 3) "d" 127.0.0.1:6379> rpop list #移除最后一个元素(移除同样遵循栈后进先出的原则) "d" 127.0.0.1:6379> lrange list 0 -1 1) "b" 2) "a" 127.0.0.1:6379> #获取下标 127.0.0.1:6379> lrange list 0 -1 1) "b" 2) "a" 127.0.0.1:6379> lindex list 1 #通过下标获取list中的值[0,1,2,3...],注意须于插入时的坐标区分 "a" 127.0.0.1:6379> lindex list 0 "b" 127.0.0.1:6379> # llen 长度 127.0.0.1:6379> lrange list 0 -1 1) "b" 2) "a" 127.0.0.1:6379> llen list (integer) 2 127.0.0.1:6379> # lrem 移除 127.0.0.1:6379> lrange list 0 -1 1) "c" 2) "b" 3) "a" 127.0.0.1:6379> lrem list 1 a #移除list集合中指定个数的value,精确匹配 (integer) 1 127.0.0.1:6379> lrange list 0 -1 1) "c" 2) "b" 127.0.0.1:6379> # ltrim 修剪 127.0.0.1:6379> lrange list 0 -1 1) "hello3" 2) "hello2" 3) "hello1" 4) "hello" 127.0.0.1:6379> ltrim list 1 2 #通过下标截取指定的长度,注:此时list的value已被改变,只剩下截取的元素 OK 127.0.0.1:6379> lrange list 0 -1 1) "hello2" 2) "hello1" 127.0.0.1:6379> # rpoplpush 移除列表的最后一个元素,并将它移动到新的列表中 127.0.0.1:6379> lrange list 0 -1 1) "hello3" 2) "hello2" 3) "hello1" 4) "hello" 127.0.0.1:6379> rpoplpush list otherlist "hello" 127.0.0.1:6379> lrange list 0 -1 1) "hello3" 2) "hello2" 3) "hello1" 127.0.0.1:6379> lrange otherlist 0 -1 1) "hello" 127.0.0.1:6379> # lset 将列表中指定下标的值替换为另一个值(更新) 127.0.0.1:6379> exists list #先判断列表是否存在 (integer) 0 127.0.0.1:6379> lset list 0 hello #如果列表不存在,则会报错 (error) ERR no such key 127.0.0.1:6379> lpush list hello (integer) 1 127.0.0.1:6379> lrange list 0 -1 1) "hello" 127.0.0.1:6379> lset list 0 nihao #如果存在,更新当前下标的值 OK 127.0.0.1:6379> lrange list 0 -1 1) "nihao" 127.0.0.1:6379> lset list 1 xiexie #如果要更新值的下标不存在,则报错 (error) ERR index out of range 127.0.0.1:6379> # linsert 将具体的值插入到列表中某个元素的前面或后面 127.0.0.1:6379> lrange list 0 -1 1) "hello" 2) "world" 127.0.0.1:6379> linsert list before world sunxiaochuan (integer) 3 127.0.0.1:6379> lrange list 0 -1 1) "hello" 2) "sunxiaochuan" 3) "world" 127.0.0.1:6379> linsert list after world liubo (integer) 4 127.0.0.1:6379> lrange list 0 -1 1) "hello" 2) "sunxiaochuan" 3) "world" 4) "liubo" 127.0.0.1:6379>
2021年01月02日
63 阅读
0 评论
0 点赞
2021-01-02
Redis基本数据类型String
String127.0.0.1:6379> set name sunxiaochuan OK 127.0.0.1:6379> get name "sunxiaochuan" 127.0.0.1:6379> append name ",chouxiang" #追加字符串,如果当前字符串不存在,就相当于set key (integer) 22 127.0.0.1:6379> get name "sunxiaochuan,chouxiang" 127.0.0.1:6379> strlen name #获取字符串长度 (integer) 22 #自增 i++ #步长 i+= 127.0.0.1:6379> incr views #自增1 (integer) 1 127.0.0.1:6379> incr views (integer) 2 127.0.0.1:6379> decr views (integer) 1 127.0.0.1:6379> decr views (integer) 0 127.0.0.1:6379> decr views (integer) -1 127.0.0.1:6379> decrby views 5 #设置步长 (integer) -6 127.0.0.1:6379> incrby views 10 (integer) 4 127.0.0.1:6379> #字符串范围 range 127.0.0.1:6379> set test "hello world" OK 127.0.0.1:6379> get test "hello world" 127.0.0.1:6379> getrange test 0 5 #截取字符串[0,5] "hello " 127.0.0.1:6379> 127.0.0.1:6379> getrange test 0 -1 #获取全部字符串 "hello world" 127.0.0.1:6379> #替换 127.0.0.1:6379> set name sunxiaochuan OK 127.0.0.1:6379> get name "sunxiaochuan" 127.0.0.1:6379> setrange name 1 abc #替换指定位置开始的字符串 (integer) 12 127.0.0.1:6379> get name "sabciaochuan" 127.0.0.1:6379> #setex(set with expire) #设置过期时间 #setnx(set if not exist) #如果不存在,设置值为xxx 127.0.0.1:6379> setex name 10 "liubo" #设置name的值为liubo,10秒后过期 OK 127.0.0.1:6379> ttl name (integer) 7 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> setnx name01 "sun" #如果name01不存在,则创建 (integer) 1 127.0.0.1:6379> keys * 1) "name01" 127.0.0.1:6379> setnx name01 "liu" #name01已存在,再次创建时失败 (integer) 0 127.0.0.1:6379> get name01 "sun" 127.0.0.1:6379> 127.0.0.1:6379> mset A a B b C c #同时设置多个值 OK 127.0.0.1:6379> keys * 1) "B" 2) "A" 3) "C" 127.0.0.1:6379> mget A B C #同时获取多个值 1) "a" 2) "b" 3) "c" 127.0.0.1:6379> msetnx A a D d #msetnx是一个原子性操作,要么都成功,要么都失败 (integer) 0 127.0.0.1:6379> get D (nil) 127.0.0.1:6379> #对象 #设置一个id为1的对象,json字符串来保存属性,方式一 127.0.0.1:6379> set user:1 {name:ceshi,age:3} #方式二 user:{id}:{filed} 127.0.0.1:6379> mset user:1:name ceshi user:1:age 3 OK 127.0.0.1:6379> mget user:1:name user:1:age 1) "ceshi" 2) "3" 127.0.0.1:6379> #getset 先get再set 127.0.0.1:6379> getset name sunxiaochuan #如果不存在值,返回null (nil) 127.0.0.1:6379> get name "sunxiaochuan" 127.0.0.1:6379> getset name liubo #如果存在值,获取原来的值,并设置新的值 "sunxiaochuan" 127.0.0.1:6379> get name "liubo" 127.0.0.1:6379> String除了以上用法,还可以用于计数器,多单位数量统计等。
2021年01月02日
53 阅读
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日
100 阅读
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 点赞
1
2
3
4
...
6