当前位置:网站首页>Detailed explanation of JDBC function classes
Detailed explanation of JDBC function classes
2022-07-21 00:38:00 【Soup key】
Catalog
DriverManager Drive management objects
Connection Database connection object
Statement perform sql Object of statement
1. Judge whether there is data in the result set
2. Get the data in the result set
DriverManager Drive management objects
1. Registration drive
- Register the given driver
- static void registerDriver(Driver driver)
- stay com.mysql.jdbc.Driver This static code block exists in the class
- Static code blocks are used as classes are used
- So you can register the operation of the driver
- So write code to use :
- Class.forName("com.mysql.jdbc.Driver");
- Be careful :
- We don't need to pass DriverManager Call static methods registerDriver(), Because as long as Driver Class is used , Will execute its static code block to complete the registration of the driver
- MySQL5 After that, you can omit the steps of registering the driver , stay jar In bag , There is one. java.sql.Driver The configuration file , The document specifies com.mysql.jdbc.Driver
2. Get database connection
- There is such a static method
- static Connection getConnection(String url, String user, String password)
- Return value :Connection( Database connection object )
- Parameters :
- url
- Specify the path of the connection
- grammar :jdbc:mysql://ip Address ( domain name ): Port number / Database name
- user
- user name
- password
- password
Connection Database connection object
1. Get the performer object
- Get the normal performer object
- Statement create Statement();
- Get the precompiled performer object
- PrepareStatement prepareStatement(String sql);
2. Manage affairs
- Open transaction
- setAutoCommit(Boolean autoCommit);
- Parameter is false, Open transaction
- Commit transaction
- commit();
- Roll back the transaction
- rollback();
3. Release resources
- Release the database connection object immediately
- void close();
Statement perform sql Object of statement
1. perform DML sentence
- int executeUpdate(String sql);
- Return value :
- Returns the number of rows affected
2. perform DQL sentence
- ResultSet executeQuery(String sql);
- Return value ResultSet: Encapsulate the results of the query
- Parameters sql: It can be executed select sentence
3. Release resources
- Release the performer object immediately
- void close();
ResultSet Result set object
1. Judge whether there is data in the result set
- Boolean next();
- There's data coming back true, And move the index down one line
- No data returned false
2. Get the data in the result set
- xxx getXxx(" Name ");
- xxx Representative data type ( To get a column of data , The data type of this column )
- for example :
- String getString("name");
- int getInt("age");
3. Release resources
- Release the result set object immediately :
- void close();
边栏推荐
- Test / development programmer Xiao Zhang's blind date
- 导入图像方法
- Two duplicate operations with different functions in blender
- 央视新闻《广州开住宿手撕定额发票》新闻频道_人民网
- 11、gin中间件
- Centos8 install MySQL
- DeiT:注意力也能蒸馏
- Overwintering samples of game companies: has going to sea and boutique become a new growth point?
- Lua code add comment rule
- cpolar应用实例之多设备数据采集
猜你喜欢
LeetCode-数组中数字出现的次数(单身狗问题)
APP UI自动化测试常见面试题,或许有用呢~
Test / development programmer Xiao Zhang's blind date
Developers must read: 2022 mobile application operation growth insight white paper
Chapter 8: monkey climbing N-level hierarchical recursion, finding the Zeng sequence of the simplest true fraction of the denominator [a, b], Fibonacci sequence recursion solution, Fibonacci sequence
EL & JSTL: summary of El expression
Multi device data acquisition of cpolar application examples
小程序“getLocation:fail fail:require permission desc“获取请求地址失败
Yolov5 trains its own VOC dataset
10、gin快速入门
随机推荐
EasyCVR视频广场设备列表无法滚动和加载是什么原因?
性能测试报告包括哪些内容?模板范文哪里找?看这里
10. Gin quick start
央视新闻《杭州开餐饮手撕定额发票》新闻频道_人民网
Installation de MySQL par centos8
央视新闻《武汉开餐饮手撕定额发票》新闻频道_人民网
Without available task slots, what will happen to Flink's new tasks?
怎么使用mySQL语句导出表
Common interview questions for app UI automated testing may be useful~
企业应积极探索,把握元宇宙新业态与新趋势
央视新闻《苏州开餐饮手撕定额发票》新闻频道_人民网
2022.7.19-----leetcode. seven hundred and thirty-one
"Collection of Architects"
Typeof and keyof
QT_ code
The applet "getlocation:fail fail: require permission desc" failed to get the requested address
央视新闻《青岛开住宿手撕定额发票》新闻频道_人民网
[SWPU2019]Web1-1|SQL注入
. Net uses its own Di batch injection service and backgroundservice
el-cascader 级联选择器动态加载数据及回显数据方法(最全概括)<grootbaby>