当前位置:网站首页>API supplement of JDBC
API supplement of JDBC
2022-07-25 10:54:00 【Hua Weiyun】
Four 、ResultSet
ResultSet( Result set object ) effect :
1. Encapsulates the DQL The result of the query statement
ResultSet stmt.executeQuery(sql): perform DQL sentence , return ResultSet object
Get query results
boolean next():(1) Move the cursor forward one line from the current position (2) Judge whether the current line is a valid line
Return value : The current row has data returned true, There is currently no data returned false.
xxx getXxx( Parameters ): get data
explain :xxx Represents the data type ; Such as int getInt( Parameters );String getString( Parameters );
Parameters : about int Is the number of the column , from 1 Start , about String Is the name of the column .
Use steps :
1、 Move the cursor down one line , And judge whether the line has data :next()
2、 get data :getXxx( Parameters )
Example :
example :
In the database emp surface
After running :
ResultSet Case study
demand : Inquire about account Account data , Encapsulated in the Account In the object , And store it in ArrayList Collection
Create a pojo package , Used to store objects .
Created a class , Provide getSet Method
jdbc In the class created under the package
Running results :
5、 ... and 、PreparedStatement
PreparedStatement effect :
1、 precompile SQL Statement and execute : The prevention of SQL Injection problem
SQL Inject
SQL Injection is to modify pre-defined by operating input SQL sentence , The method used to execute code to attack the server .
Demonstrate normal login :
First, data record kc_db1 Under the emp The table is :
Running results :
Enter other ( The reason for the failure is that there is no account with this password in the database ):
sql Inject Demo :
For this article sql It's not about passwords , Any account number
Running results :
This article SQL The sentence is :select *from emp where ename=' A casual name 'and password=' ' or '1'='1'
sql The essence of injection is to change the original SQL sentence , Join in or after 1=1 Always true , So this sentence is true
PreparedStatement solve SQL Inject
① obtain PreparedStatement object
② Set parameters
PreparedStatement object :setXxx( Parameters 1, Parameters 2): Expressed as a parameter 1(? The location of ) Assign value to parameter 2
Xxx: data type ; arbitrarily setInt( Parameters 1, Parameters 2)
Parameters :
- Parameters 1: Express ? Location number of , from 1 Start
- Parameters 2: ? Value
③ perform sql
executeUpdate();/excuteQuery(); There is no need to pass... In parentheses sql.
Create a class :
Running results :
This prevents sql Inject ,setXxx The parameters passed in will be escaped , Not spliced into strings, but \' or\ ' 1\' = \' 1\'
Enter the correct :
PrepareStatement principle
PrepareStatement benefits :
1、 precompile SQL, Higher performance
2、 prevent sql Inject .
my.ini The configuration file can see the log
The precompile function is off by default
①:PreparedStatement Precompile function Turn on :userServerPrepStmts=true
stay sql sentence ? Then write the parameters
When you open it, you will prepare precompile :
After closing, there is no Prepare Stage
边栏推荐
- User preferences
- 【蓝桥杯集训100题】scratch太极图 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第22题
- HCIP(13)
- Flask框架——flask-caching缓存
- 2. Conditional statements of shell script
- UE4 quickly find the reason for packaging failure
- 我为OpenHarmony 写代码,战“码”先锋第二期正式开启!
- DHCP configuration (take Huawei ENSP as an example)
- 哥廷根大学提出CLIPSeg:一个使用文本和图像prompt能同时作三个分割任务的模型
- I wrote code for openharmony, and the second phase of "code" pioneer officially opened!
猜你喜欢

The practice of asynchronous servlet in image service

Using px2rem does not take effect

AI technology stack is too huge! Wu Enda gives career planning: lifelong learning

HCIA实验(06)

3.跟你思想一样DNS域名解析服务!!!

3. Believe you can understand! Circular statements and functions of shell scripts, arrays, bubble sorting

Attention is all you need paper intensive reading notes transformer

Wechat applet wxprase contains files that cannot be solved by clicking

Trojang attack on neural networks paper reading notes

Introduction to onnx (open neural network exchange)
随机推荐
8. SHELL file processing Three Musketeers sed
JDBC的APi补充
Install MySQL database version 5.7.29 under ubuntu20.04 system
微波技术基础实验一 滤波器的设计
树形动态规划
2021 CEC written examination summary
【蓝桥杯集训100题】scratch太极图 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第22题
哥廷根大学提出CLIPSeg:一个使用文本和图像prompt能同时作三个分割任务的模型
Using px2rem does not take effect
redis 哨兵,高可用的执行者
如何通过开源数据库管理工具 DBeaver 连接 TDengine
Configuration of static routes (take Huawei ENSP as an example)
Analysis of event channel principle in Kraken
js 哈希表 01
HCIP实验(04)
HCIP (01)
二合一的集度,任重道远
2021 CEC笔试总结
2021 Niuke written examination summary 02
Openstack Skyline 组件安装












