当前位置:网站首页>Explanation of JDBC classes
Explanation of JDBC classes
2022-07-28 10:59:00 【Camellia——】
JDBC Operation steps of :
1) Registration drive
java.sql.DriverManager: Driver management ( Manage a group of JDBC Service )
Registration driven method :
public static void registerDriver(Driver driver):
Formal parameter passing It's the interface , You need to change the sub implementation class object of the interface
Drive provided Jar package :com.mysql.jdbc.Driver implements java.sql.Driver Interface
Normal format : ( disadvantages : It's equivalent to registering twice )
Driver driver = new com.mysql.jdbc.Driver() ;
// DriverManager.registerDriver(driver);
Bottom source :
Package name :com.mysql.jdbc
public class Driver implements java.sql.Driver {
Static code block : Load the Driver Class , Statically related code is executed first !
static {
try {
// Use the driver management to register the driver
java.sql.DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}
}
After the optimization : Using the idea of reflection : Just load com.mysql.jdbc.Driver This class is ok !
Class.forName("com.mysql.jdbc.Driver") ;// Ensure the downward compatibility of versions , It is suggested to always give this sentence !
2) Drive management DriverManager Get the connection object of the database :Connection(java.sql)
Drive management DriverManger : Manage a group of JDBC Service
public static Connection getConnection(
String url,String user,String password): Get the connection
url: Uniform resource locator : Namely uri A subset of
Use url:
jdbc:mysql:// domain name : Port number / Database name ( The library must exist !)
There are a lot of agreements :
ftp://
http:// domain name : Port number / Specific request address for access
mail: Email protocol
thunder:// Thunder Association ...
file:// Local file protocol
...
uri: Network resources are a general term !
http://localhost:8080/login :URL
/login: uri
user: user name : The name of the user connecting to the database :root
password: The password used to connect to the database
3)Connection: Connection object java.sql.Connection
Represents a session with a database ( Connect ), You can get the metadata information of the current linked database ( The structure of the table / The field type of the table ..)
Member method :
Statement createStatement(): establish Statement Perform object
And will specify sql Send to the specified database
PreparedStatement prepareStatement(String sql): The parameter sql Statement to execute
Send to database , And get the precompiled object
DatabaseMetaData getMetaData(): Get metadata information related to the database
It includes the structure of some databases and tables ....
4)Statement:java.sql.Statement
Perform object
Execute static sql sentence
give an example :
"update account set balance = balance + 500 where id = 1;
id Value , to balance+500 Value ,( Hard encoding )
Member method :
int executeUpdate(String sql): Common methods
in the light of DML sentence :insert,update,delete, With returned results
Can perform the most basic DDL sentence , There is no content returned !
ResultSet executeQuery(String sql): Special execution DQL sentence :select..
The result returned : Result set object ( Data table of database result set )
5)PreparedStatement Perform object ( Precompiled objects ) extends Statement
precompiled SQL Object of statement .
Give parameterized sql Assign a value
sql:
insert into Table name (name,age,gender) values(?,?,?) ; Placeholder
publi void setXXX( The first parameter , actual value ) ;
ResultSet executeQuery(): perform DQL sentence
int executeUpdate(): perform DML Statement will return the result : Affected the number of rows
Appoint DDL sentence , The return is 0
6)ResultSet: The data table of the result set generated after the query (java.sql.xx)
边栏推荐
- Sword finger offer 35. replication of complex linked list
- 剑指 Offer 09. 用两个栈实现队列
- Blue Bridge Cup embedded Hal library USART_ RX
- Ten questions about low code: tell everything about low code!
- Inventory: 144 free learning websites, the most complete collection of resources in the whole network
- BOM部分属性及理解
- JSON preliminary understanding
- GKNoiseMap
- GKVoronoiNoiseSource
- 蓝桥杯电子类嵌入式第十届省赛
猜你喜欢

Advance.ai sailing guide helps enterprises sail to Indonesia and grasp half of the Southeast Asian market

Learn these analysis methods and models, and no longer have no ideas when encountering problems

Inventory: exciting data visualization chart

GKSpheresNoiseSource

GKConstantNoiseSource

keil和IAR中lib库文件的生成和使用

蓝桥杯嵌入式-HAL库-SYSTICK

零代码 | 轻松实现数据仓库建模,搭建BI看板

11_ UE4 advanced_ Change male characters to female characters and modify the animation

6. MapReduce custom partition implementation
随机推荐
Semeval 2022 | introducing knowledge into ner system, aridamo academy won the best paper award
cortex-M4与cortex-A7内核启动流程分析
Start from scratch blazor server (2) -- consolidate databases
The Xiongguan pass is like an iron road, and now we are going to cross it from the beginning
Status Notice ¶
Solving the optimal solution of particle swarm optimization
GKConstantNoiseSource
Eslint, Eslint中文文档
Installation points and precautions of split angle probe
数组相关的知识点
nodejs:搭建express 服务,设置session以及实现退出操作
Sword finger offer 35. replication of complex linked list
FHWY工作日进度表
剑指 Offer 06. 从尾到头打印链表
Install MySQL based on docker
剑指 Offer 35. 复杂链表的复制
GKLinearCongruentialRandomSource
Yan reported an error: could not find any valid local directory for nmprivate/
Blue Bridge Cup embedded Hal library systick
Two years of crud, two graduates, two months of preparation for the interview with ALI, and fortunately won the offer grading p6