当前位置:网站首页>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
边栏推荐
- 2021 Niuke written examination summary 02
- 9. Shell text processing three swordsmen awk
- Analysis of event channel principle in Kraken
- Keras deep learning practice (16) -- detailed explanation of self encoder
- js 集合
- redis 哨兵,高可用的执行者
- 【高并发】如何实现亿级流量下的分布式限流?这些理论你必须掌握!!
- 三万字速通Servlet
- 6. PXE combines kickstart principle and configuration to realize unattended automatic installation
- Using px2rem does not take effect
猜你喜欢

Configuration of static routes (take Huawei ENSP as an example)

HCIP(13)

Introduction to onnx runtime

Cloud native ide: the first general codeless development platform of IVX for free
![[Blue Bridge Cup training 100 questions] scratch Taiji diagram Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question No. 22](/img/d5/56173050f62d5b6fa336ff8d257fca.png)
[Blue Bridge Cup training 100 questions] scratch Taiji diagram Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question No. 22
C class library generation, use class library objects to data bind DataGridView

ESP32C3基于Arduino框架下的 ESP32 RainMaker开发示例教程

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

HCIA实验(09)

The most comprehensive UE4 file operation in history, including opening, reading, writing, adding, deleting, modifying and checking
随机推荐
7. Shell practical gadget cut, etc
软件测试技术之跨平台的移动端UI自动化测试(上)
2021 qunar written examination summary
Redis usage scenario
2021 CEC written examination summary
4. Children next door will know all kinds of shell symbols {}[], etc
6. PXE combines kickstart principle and configuration to realize unattended automatic installation
Upgrade glibc 2.29 checking LD_ LIBRARY_ Path variable... Contains current directory error solution
HCIA实验(10)NAT
ONNX(Open Neural Network Exchange)介绍
2021 牛客网笔试总结 02
Add CONDA virtual environment env to the Jupiter kernel
微信小程序版本更新如何通知用户?
[strategic mode] like Zhugeliang's brocade bag
Pytorch tensor list is converted to tensor list of tensor to tensor using torch.stack()
DHCP configuration (take Huawei ENSP as an example)
【Servlet】请求的解析
UE4 external open EXE file
5. This simple "echo" usage, can the child next door!
The most comprehensive UE4 file operation in history, including opening, reading, writing, adding, deleting, modifying and checking












