当前位置:网站首页>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 .
边栏推荐
- The difference between sizeof and strlen in C language
- Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
- 2.13 simulation summary
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
- Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
- 07 单件(Singleton)模式
- Apt installation ZABBIX
- Universal crud interface
- Atcoder beginer contest 233 (a~d) solution
- SQL table name is passed as a parameter
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Advanced technology management - what is the physical, mental and mental strength of managers
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
RobotFramework入门(三)WebUI自动化之百度搜索
QT release exe software and modify exe application icon
Referenceerror: primordials is not defined error resolution
2022.02.13
【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
力扣今日題-729. 我的日程安排錶 I
随机推荐
Is there a completely independent localization database technology
Template_ Quick sort_ Double pointer
Microservice registration and discovery
After changing the GCC version, make[1] appears in the compilation: cc: command not found
会员积分营销系统操作的时候怎样提升消费者的积极性?
故障分析 | MySQL 耗尽主机内存一例分析
[network security interview question] - how to penetrate the test file directory through
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
有没有完全自主的国产化数据库技术
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
Six stone management: why should leaders ignore product quality
RobotFramework入门(二)appUI自动化之app启动
CSP numeric sort
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Summary of Bible story reading
SQL table name is passed as a parameter
微服务间通信
550 permission denied occurs when FTP uploads files, which is not a user permission problem
JS events (add, delete) and delegates