当前位置:网站首页>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();
}
}
边栏推荐
猜你喜欢

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

Some settings about postfix completion code template in idea

Currying Scala functions
[email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT"/>NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT

Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand

Coggle 30 Days of ML 7月竞赛学习

Configuring FTP, enterprise official website, database and other methods for ECS

Redis cache penetration, cache breakdown, cache avalanche

From 5 seconds to 1 second, the system flies

Solve the problem of win10 wsl2 IP change
随机推荐
hutool对称加密
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
聊聊领域驱动设计
POI replacing text and pictures in docx
延时队列`DelayQueue`
Nature、science、cell旗下刊物
Caldera installation and simple use
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?
multiprocessing. Detailed explanation of pool
Talk about Domain Driven Design
IDEA连接数据库报错
How to download opencv? How to configure opencv after downloading?
Window right click management
Coggle 30 Days of ML 7月竞赛学习
【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
Get the query parameter in the address URL specify the parameter method
poi导出excle
SQL injection bypass (I)
Win10 remote connection to ECS
Rust中的Pin详解