当前位置:网站首页>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 .
边栏推荐
- A doctor's 22 years in Huawei
- 微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
- #PAT#day10
- High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
- Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
- [kubernetes series] learn the exposed application of kubernetes service security
- Trends in DDoS Attacks
- Introduction to robotframework (III) Baidu search of webui automation
- Yyds dry inventory comparison of several database storage engines
- 2.12 simulation
猜你喜欢
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
淘宝焦点图布局实战
Maturity of master data management (MDM)
Referenceerror: primordials is not defined error resolution
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
深度解析链动2+1模式,颠覆传统卖货思维?
主数据管理(MDM)的成熟度
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
随机推荐
Function knowledge points
C语言sizeof和strlen的区别
不赚钱的科大讯飞,投资价值该怎么看?
How does yyds dry inventory deal with repeated messages in the consumption process?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
Bigder: I felt good about the 34/100 interview, but I didn't receive the admission
Redis installation
Communication between microservices
Six stone management: why should leaders ignore product quality
PMP practice once a day | don't get lost in the exam -7.5
Zhang Lijun: penetrating uncertainty depends on four "invariants"
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Universal crud interface
07 单件(Singleton)模式
【若依(ruoyi)】启用迷你导航栏
C language - Blue Bridge Cup - promised score
CSP numeric sort
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers