当前位置:网站首页>JDBC transaction commit case
JDBC transaction commit case
2022-06-27 07:21:00 【Qingyun 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 Get the connection
String url = "jdbc:mysql://IP:Port/db_name";
String username = "username ";
String password = "password ";
Connection conn = DriverManager.getConnection(url, username, password);
//2 sql sentence
String sql = "update account set age=18 where id=1";
//3 Access to perform sql The object of
Statement stmt = conn.createStatement();
try {
// Open transaction
conn.setAutoCommit(false);
//4 perform sql
int count = stmt.executeUpdate(sql);
//5 Print processing results
System.out.println(count);
// Commit transaction
conn.commit();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
//6 Release resources
stmt.close();
conn.close();
}
}
边栏推荐
- Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
- Machine learning
- pytorch Default process group is not initialized
- One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
- Fractional Order PID control
- yarn create vite 报错 ‘D:\Program‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件
- HTAP in depth exploration Guide
- POI export excle
- Guava scheduled task
- 2022 CISP-PTE(一)文件包含
猜你喜欢
YOLOv6又快又准的目标检测框架 已开源
Interviewer: you use Lombok every day. What is its principle? I can't answer
Meaning of 0.0.0.0:x
(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
volatile 和 synchronized 到底啥区别?
Memory barrier store buffer, invalid queue
Interviewer: how to never migrate data and avoid hot issues by using sub database and sub table?
Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
正斜杠反斜杠的由来
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
随机推荐
如何优雅的写 Controller 层代码?
专业四第二周自测
HTAP Quick Start Guide
在线文本数字识别列表求和工具
Rust中的Pin详解
Manim math engine
JDBC参数化查询示例
2022 cisp-pte (I) document contains
JDBC事务提交事例
POI replacing text and pictures in docx
Compatibility comparison between tidb and MySQL
On gpu: historical development and structure
Get the query parameter in the address URL specify the parameter method
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
通过uview让tabbar根据权限显示相应数量的tabbar
Idea method template
jupyter notebook文件目录
Overview of database schema in tidb
SQL考勤查询间隔一小时
Gérer 1000 serveurs par personne? Cet outil d'automatisation o & M doit être maîtrisé