当前位置:网站首页>Detailed use of dbutils # yyds dry goods inventory #
Detailed use of dbutils # yyds dry goods inventory #
2022-07-06 02:48:00 【Liang Yunliang】
DBUtils
brief introduction
DBUtils yes Java Database operation utility in programming , Small, simple and practical .DBUtils Encapsulates the JDBC The operation of , To simplify the JDBC operation , Can reduce the 60% Code above .
DBUtils Introduction to three core functions
- QueryRunner: Core classes provide access to sql Statement operation API
- QueryRunner(DataSourcr ds): Provide data sources ( Connection pool ),DbUtils Bottom layer automatic maintenance connection connection
- update(String sql,Obj…params): Perform an update operation
- query(String sql,ResultSetHandler<T>rsh,Object…panrams): Perform query operation
- ResultSetHandler: Result set processing class , Used for definition select After the operation , How to encapsulate result sets
- ArrayHandler: Put the first row of data in the query result set into an array . Suitable for 1 Bar record .
- ArrayListHandler: Put each row of data in the query result into an array , Then put the array into the collection List in . It is suitable for taking multiple records .
- BeanHandler: Encapsulate the first row of data in the result set into a corresponding JavaBean In the example
- BeanListHandler: Encapsulate each row of data in the result set into a corresponding JavaBean In the example , Then store these objects in List in .
- MapHandler: Encapsulate the first row of data in the result set into a Map in ,key Is the column name ,value Is the corresponding value .
- MapListHandler: Save each row of the query result into a map in , Key is column name , The value is the value of each column ; And then map Deposit in list in
- ColumnListHandler: Store the data of a column in the result set in List in .
- KeyedHandler(name): Encapsulate each row of data in the result set into a Map in (List<Map>), And then put these map Save one more map in , Its key For the specified column .
- ScalarHandler: Put a column in the first row of the result set into an object .// a key
- DBUtils: Tool class , Defines methods for closing resources and transactions .
Example : use Druid and dbutils Realize to Dept Of CRUD
First step :Dept.java:<a rel=“nofollow” href=“ https://blog.csdn.net/lianghecai52171314/article/details/101469279”>Dept Source code </a>
The second step : New projects , Join in Maven rely on :
The second step : stay resources Create under directory mysql.properties, The code is as follows :
The third step : Create a database connection tool class :
Step four : Test transactions
Step five :DeptDaoImpl.java
dynamic SQL And static SQL
SQL Statements can be divided into static statements from the perspective of compilation and operation SQL and dynamic SQL, So-called SQL The dynamic and static state of , Refer to SQL When statements are compiled and executed .
These two kinds of SQL In the way of use 、 Operation mechanism and performance have their own characteristics :
- static state SQL: static state SQL Statements are generally used in embedded systems SQL Application , Before the program runs ,SQL Statements must be certain when programming , for example SQL The column and table names involved in the statement must exist . static state SQL Statement is compiled before the application runs , The compiled results are stored in the database . Then the program runs , The database will directly execute the compiled SQL sentence , Reduce runtime overhead .
- dynamic SQL: dynamic SQL Statements are compiled and executed while the application is running , for example , Use DB2 Interactive tools for CLP When accessing the database , User entered SQL The statement is indeterminate , therefore SQL Statements can only be compiled dynamically . dynamic SQL More applications , common CLI and JDBC Applications use dynamic SQL.
static state sql The access path of is determined before running , And dynamic sql The access path is dynamically generated at run time .
Be careful : stay SQL If some parameters are not determined , Such as "select * from t1 where c1>? and c2<?", This statement is static SQL, Not dynamic SQL, Although the value of individual parameters is not known , But the whole SQL The structure of has been determined , The database can be compiled , In the execution phase, you only need to add the values of individual parameters .
边栏推荐
- C language - Blue Bridge Cup - promised score
- Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
- 【Unity3D】GUI控件
- [untitled] a query SQL execution process in the database
- 张丽俊:穿透不确定性要靠四个“不变”
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
- 纯Qt版中国象棋:实现双人对战、人机对战及网络对战
- Pat 1046 shortest distance (20 points) simulation
- GifCam v7.0 极简GIF动画录制工具中文单文件版
- Data preparation
猜你喜欢
[ruoyi] enable Mini navigation bar
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Yyds dry inventory comparison of several database storage engines
Pure QT version of Chinese chess: realize two-man, man-machine and network games
MySQL advanced notes
[matlab] access of variables and files
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
RobotFramework入门(三)WebUI自动化之百度搜索
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
随机推荐
有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
故障分析 | MySQL 耗尽主机内存一例分析
Apt installation ZABBIX
inherited constructors
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
力扣今日题-729. 我的日程安排表 I
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
The difference between sizeof and strlen in C language
A copy can also produce flowers
ReferenceError: primordials is not defined错误解决
Taobao focus map layout practice
解决:AttributeError: ‘str‘ object has no attribute ‘decode‘
球面透镜与柱面透镜
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
一个复制也能玩出花来
在GBase 8c数据库中使用自带工具检查健康状态时,需要注意什么?
How to check the lock information in gbase 8C database?
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)