当前位置:网站首页>JDBC common interview questions
JDBC common interview questions
2022-07-01 05:29:00 【lanleihhh】
JDBC Frequently asked questions
Database connection pool
Allow the program to reuse... In the connection pool Database connection , Instead of destroying the original connection , Create a new connection

working principle
When the server starts , Create a certain number of database connections Connection, Unified management ( Abstract out a concept of connection pool ).
When the client needs to connect , Return an idle connection from the pool , Mark it as busy
If there is no idle connection , Just create a certain number of connections ( By configuration parameters )
After the connection is no longer used , Mark it as free , Other threads can use this connection
When the number of connections requested by the client exceeds the maximum number of connections , The request will be added to the waiting queue
Implementation scheme
Another blog : Simple implementation of database connection pool
JDBC Driving process of
- Registration drive
Class.forName("com.mysql.jdbc.Driver")
Reflection to create Driver object , load Driver Class time , Execute static methodsDriverManager.registerDriver(new Driver());Registration drive - Establishing a connection
adopt Connection build ⽴ ConnectConnection coon = DriverManager.getConnection(URL,USER,PWD); - Create run SQL The object of Statement
Statement statement = coon.prepareStatement(sql); - perform SQL sentence
statement.executeQuery();Inquire about ; return ResultSetstatement.executeUpdate();Additions and deletions ; Returns the number of rows affected - Processing result set
ResultSet Save the results of execution
The method of traversing query results isresultSet.next() - Release resources
Release database connection objectConnection
Release execution SQL The object ofStatement
Release the objects of the result setResultSet
Statement and PreparedStatement difference
PreparedStatement Interface inherited Statement Interface
It's all through Connection Connect object to get
Readability 、 Maintainability
Statement Only strings can be used to splice parameters
stmt.executeUpdate("insert into tb_name (col1,col2,col2,col4) " +
"values ('"+var1+"','"+var2+"',"+var3+",'"+var4+"')");
PreparedStatement Use placeholders , Dynamic setting parameters
ps = con.prepareStatement("insert into tb_name (col1,col2,col2,col4) " +
"values (?,?,?,?)");
ps.setString(1, var1);
ps.setString(2, var2);
ps.setString(3, var3);
ps.setString(4, var4);
performance
- Statement perform SQL Statement is not precompiled , Every execution needs to be recompiled
- PrepareStatement Will the precompiled SQL sentence , When executed many times , Just run , Don't compile it every time
Security
because Statement Concatenate parameters with strings , It's easy to get caught. SQL Inject
PrepareStatement Precompiling , Only one value can be inserted per placeholder , Will filter other statements ( Improved security )
JDBC How to page medium and large amounts of data
边栏推荐
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- Causes of short circuit of conductive slip ring and Countermeasures
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- Vmware workstation network card settings and three common network modes
- Rust基础入门之变量绑定与解构
- Typeorm framework
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
- Application and principle of ThreadPoolExecutor thread pool
- JS random verification code
- 在Rainbond中一键部署高可用 EMQX 集群
猜你喜欢

Typeorm framework

Set集合詳細講解

提高企业产品交付效率系列(1)—— 企业应用一键安装和升级

Leetcode top 100 question 2 Add two numbers

Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting

智慧运维:基于 BIM 技术的可视化管理系统

多表操作-外键级联操作

0xc000007b应用程序无法正常启动解决方案(亲测有效)

Use and principle of reentrantlock

Vmware workstation network card settings and three common network modes
随机推荐
智慧运维:基于 BIM 技术的可视化管理系统
Memtable for leveldb source code analysis
Actual combat: basic use of Redux
Unity project experience summary
Spanner 论文小结
How to meet the requirements of source code confidentiality and source code security management
el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;
QT waiting box production
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
基于TI DRV8424驱动步进电机实现调速和行程控制
Flutter can refresh data every time the interface comes in
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
Using nocalhost to develop microservice application on rainbow
Things generated by busybox
Global and Chinese market of protection circuit modules 2022-2028: Research Report on technology, participants, trends, market size and share
SSGSSRCSR区别
Unit testing with mongodb
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
Day 05 - file operation function
液压滑环的特点讲解