当前位置:网站首页>JDBC operation MySQL example
JDBC operation MySQL example
2022-06-27 07:21:00 【Qingyun ing】
One 、mysql Driver download :
Address :https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.29.zip
Two 、 Project reference
1 Create project , modular
2 hold mysql-connector-java-8.0.29.jar Copy to project
3 Introduced mysql Package add project reference
3、 ... and 、 Sample code
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 Registration drive
Class.forName("com.mysql.cj.jdbc.Driver");
//2 Get the connection
String url = "jdbc:mysql://10.1.1.1:3306/db_test";
String username = "qingyuning";
String password = "[email protected]~2022";
Connection conn = DriverManager.getConnection(url, username, password);
//3 sql sentence
String sql = "update account set age=18 where id=1";
//4 Access to perform sql The object of
Statement stmt = conn.createStatement();
//5 perform sql
int count = stmt.executeUpdate(sql);
//6 Print processing results
System.out.println(count);
//7 Release resources
stmt.close();
conn.close();
}
}
边栏推荐
- Centos7.9 install MySQL 5.7 and set startup
- Guava scheduled task
- (已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
- Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
- postgreSQL在windows系统遇到权限否认(permission denied)
- Configuring FTP, enterprise official website, database and other methods for ECS
- SQL考勤查询间隔一小时
- Optimistic and pessimistic affairs
- Yolov6's fast and accurate target detection framework is open source
- 2022 cisp-pte (II) SQL injection
猜你喜欢

2022 CISP-PTE(一)文件包含

【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评

winow10安装Nexus nexus-3.20.1-01

Win10 remote connection to ECS

小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜

How to download opencv? How to configure opencv after downloading?

MySQL

YOLOv6又快又准的目标检测框架 已开源

Process termination (have you really learned recursion? Test your recursion Foundation)

Unsafe中的park和unpark
随机推荐
Overview of database schema in tidb
【OpenAirInterface5g】RRC NR解析之RrcSetupComplete
Rust中的Pin详解
Interviewer: you use Lombok every day. What is its principle? I can't answer
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
【软件工程】山东大学软件工程复习提纲
R 语言Analyzing wine data
On gpu: historical development and structure
Meaning of 0.0.0.0:x
Classical cryptosystem -- substitution and replacement
Rust Async: smol源码分析-Executor篇
将通讯录功能设置为数据库维护,增加用户名和密码
Fractional Order PID control
多表联查--07--- Hash join
2022 cisp-pte (II) SQL injection
[openairinterface5g] rrcsetupcomplete for RRC NR resolution
Thesis reading skills
Delay queue `delayqueue`
Tidb database Quick Start Guide
How to implement redis cache of highly paid programmers & interview questions series 116? How do I find a hot key? What are the possible problems with caching?