当前位置:网站首页>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();
}
}
边栏推荐
- Visual studio vs shortcut key usage
- OPPO面试整理,真正的八股文,狂虐面试官
- 【LeetCode】Day90-二叉搜索树中第K小的元素
- Tar: /usr/local: cannot find tar in the Archive: due to the previous error, it will exit in the last error state
- 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
- JDBC参数化查询示例
- Date database date strings are converted to and from each other
- Some settings about postfix completion code template in idea
- 专业四第二周自测
- 高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
猜你喜欢
随机推荐
Difference between boundvalueops and opsforvalue
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
攻防演习防御体系构建之第二篇之应对攻击的常用策略
volatile 和 synchronized 到底啥区别?
multiprocessing. Detailed explanation of pool
manim 数学引擎
Installation and functions of uview
R 语言Analyzing wine data
专业四第二周自测
R 中的 RNA-Seq 数据分析 - 调查数据中的差异表达基因!
Apifox learning
进程终止(你真的学会递归了吗?考验你的递归基础)
View functions in tidb
延时队列`DelayQueue`
How to download opencv? How to configure opencv after downloading?
extendible hashing
Interviewer: you use Lombok every day. What is its principle? I can't answer
YOLOv6又快又准的目标检测框架 已开源