当前位置:网站首页>JDBC事务提交事例
JDBC事务提交事例
2022-06-27 06:55:00 【青云ing】
import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JDBCDemo {
public static void main(String[] args) throws Exception {
//1 获取连接
String url = "jdbc:mysql://IP:Port/db_name";
String username = "username ";
String password = "password ";
Connection conn = DriverManager.getConnection(url, username, password);
//2 sql 语句
String sql = "update account set age=18 where id=1";
//3 获取执行sql的对象
Statement stmt = conn.createStatement();
try {
//开启事务
conn.setAutoCommit(false);
//4 执行sql
int count = stmt.executeUpdate(sql);
//5 打印处理结果
System.out.println(count);
//提交事务
conn.commit();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
//6 释放资源
stmt.close();
conn.close();
}
}
边栏推荐
- 将通讯录功能设置为数据库维护,增加用户名和密码
- tracepoint
- (已解决) MINet 进行测试时报错如下 raise NotImplementedError
- When there are multiple El select, the selected value is filtered by El select, and the last selected value is filtered by the second El select
- The number of query results of maxcompute SQL is limited to 1W
- Overview of database schema in tidb
- Caldera installation and simple use
- Centos7.9 install MySQL 5.7 and set startup
- 面试官:请你介绍一下缓存穿透、缓存空值、缓存雪崩、缓存击穿的,通俗易懂
- Optimistic and pessimistic affairs
猜你喜欢

Solve the problem of win10 wsl2 IP change

mssql如何使用语句导出并删除多表数据

Interviewer: you use Lombok every day. What is its principle? I can't answer
![[openairinterface5g] rrcsetupcomplete for RRC NR resolution](/img/61/2136dc37b98260e09f3be9979492b1.jpg)
[openairinterface5g] rrcsetupcomplete for RRC NR resolution

IDEA连接数据库报错

SQL injection bypass (I)

面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…

(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘

在线文本数字识别列表求和工具

小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜
随机推荐
When there are multiple El select, the selected value is filtered by El select, and the last selected value is filtered by the second El select
Goodbye, agile Scrum
【OpenAirInterface5g】RRC NR解析之RrcSetupComplete
正斜杠反斜杠的由来
tracepoint
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
SQL 注入绕过(一)
Centos7.9安装mysql 5.7,并设置开机启动
Unrecognized VM option ‘‘
用XGBoost迭代读取数据集
Thesis reading skills
jupyter notebook文件目录
2018 mathematical modeling competition - special clothing design for high temperature operation
YOLOv6又快又准的目标检测框架 已开源
Meaning of 0.0.0.0:x
DMU software syntax highlighting VIM setting -- Learning Notes 6
The number of query results of maxcompute SQL is limited to 1W
Quick realization of Bluetooth ibeacn function
(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜