当前位置:网站首页>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 .
边栏推荐
- Single instance mode of encapsulating PDO with PHP in spare time
- 米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
- Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
- 微服务注册与发现
- Redis skip table
- Microservice registration and discovery
- Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
- The difference between sizeof and strlen in C language
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
猜你喜欢
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
[matlab] access of variables and files
RobotFramework入门(二)appUI自动化之app启动
【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
MySQL winter vacation self-study 2022 11 (9)
A doctor's 22 years in Huawei
[postgraduate entrance examination English] prepare for 2023, learn list5 words
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
GifCam v7.0 极简GIF动画录制工具中文单文件版
随机推荐
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
Apt installation ZABBIX
Installation and use tutorial of cobaltstrike-4.4-k8 modified version
Qt发布exe软件及修改exe应用程序图标
MySQL advanced notes
After changing the GCC version, make[1] appears in the compilation: cc: command not found
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
Communication between microservices
QT release exe software and modify exe application icon
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
张丽俊:穿透不确定性要靠四个“不变”
力扣今日题-729. 我的日程安排表 I
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
Elimination games
2022.02.13
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
C language - Blue Bridge Cup - promised score