当前位置:网站首页>JDBC操作Mysql示例
JDBC操作Mysql示例
2022-06-27 06:55:00 【青云ing】
一、mysql驱动下载:
地址:https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.29.zip
二、项目引用
1 创建项目,模块
2 把 mysql-connector-java-8.0.29.jar 复制到项目中
3 引入的mysql包添加项目引用
三、示例代码
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 注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2 获取连接
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 语句
String sql = "update account set age=18 where id=1";
//4 获取执行sql的对象
Statement stmt = conn.createStatement();
//5 执行sql
int count = stmt.executeUpdate(sql);
//6 打印处理结果
System.out.println(count);
//7 释放资源
stmt.close();
conn.close();
}
}
边栏推荐
- Partial function of Scala
- R 语言Analyzing wine data
- 【LeetCode】Day90-二叉搜索树中第K小的元素
- Process termination (have you really learned recursion? Test your recursion Foundation)
- View functions in tidb
- OpenCV怎么下载?OpenCV下载后怎么配置?
- MPC control of aircraft wingtip acceleration and control surface
- Centos7.9安装mysql 5.7,并设置开机启动
- Centos7.9 install MySQL 5.7 and set startup
- 仙人掌之歌——投石问路(1)
猜你喜欢

Rust Async: smol源码分析-Executor篇

Currying Scala functions

Machine learning

Coggle 30 Days of ML 7月竞赛学习
![[openairinterface5g] rrcsetupcomplete for RRC NR resolution](/img/61/2136dc37b98260e09f3be9979492b1.jpg)
[openairinterface5g] rrcsetupcomplete for RRC NR resolution

一個人管理1000臺服務器?這款自動化運維工具一定要掌握

内存屏障今生之Store Buffer, Invalid Queue

Modeling competition - optical transport network modeling and value evaluation

Interviewer: how to never migrate data and avoid hot issues by using sub database and sub table?

进程终止(你真的学会递归了吗?考验你的递归基础)
随机推荐
Apifox learning
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
IDEA连接数据库报错
guava 教程收集一些案例慢慢写 google工具类
Win10 remote connection to ECS
Delay queue `delayqueue`
Currying Scala functions
vs怎么配置OpenCV?2022vs配置OpenCV详解(多图)
解决 Win10 Wsl2 IP 变化问题
Meaning of 0.0.0.0:x
On gpu: historical development and structure
pytorch Default process group is not initialized
guava 定时任务
YOLOv6又快又准的目标检测框架 已开源
Centos7.9安装mysql 5.7,并设置开机启动
如何优雅的写 Controller 层代码?
攻防演习防御体系构建之第一篇之介绍和防守的四个阶段
Thesis reading skills
Hutool symmetric encryption
面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…