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

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

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

【软件工程】山东大学软件工程复习提纲

Oppo interview sorting, real eight part essay, abusing the interviewer

Modeling competition - optical transport network modeling and value evaluation

多表联查--07--- Hash join

云服务器配置ftp、企业官网、数据库等方法

解决 Win10 Wsl2 IP 变化问题

yarn create vite 报错 ‘D:\Program‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

面试官:请你介绍一下缓存穿透、缓存空值、缓存雪崩、缓存击穿的,通俗易懂
随机推荐
Transaction overview of tidb
Date database date strings are converted to and from each other
Classical cryptosystem -- substitution and replacement
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
Talk about Domain Driven Design
pytorch Default process group is not initialized
小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜
Goodbye, agile Scrum
Basic SQL operations in tidb
manim 数学引擎
进程终止(你真的学会递归了吗?考验你的递归基础)
HTAP in depth exploration Guide
DMU software syntax highlighting VIM setting -- Learning Notes 6
guava 定时任务
一线大厂面试官问:你真的懂电商订单开发吗?
HTAP Quick Start Guide
专业四第二周自测
Centos7.9安装mysql 5.7,并设置开机启动
Unrecognized VM option ‘‘
thrift