当前位置:网站首页>JDBC connection
JDBC connection
2022-07-26 20:59:00 【Camellia——】
package com.lin.jdbc_01;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/*
* JDBC Basic introduction to use
* 1) The load driver
* 2) Get database connection object
* 3) Get ready sql sentence
* 4) Get execution object
* 5) Perform object sql sentence
* 6) Return results
* 7) Release
* */
public class JDBCDemo {
public static void main(String[] args) throws Exception {
// 1) Load database driver :com.mysql.jdbc: The underlying implementation of the driver class is sun company Driver Interface
Class.forName("com.mysql.jdbc.Driver");
// 2) Get database connection object
/*
public static Connection getConnection
(String url,String user,String password)throws SQLException
Parameters 1:url: Connected to the database url Address ( Uniform resource locator )"jdbc:mysql://localhost:3306/ Database name "
Parameters 2: User name to connect to the database root
Parameters 3: Password to connect to the database
*/
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb_02", "root", "123456");
// 3) Get ready sql sentence
String sql="update emp set salary=salary+500 where id=6;";
// 4) Get the execution object through the database connection object
// Statement createStatement()throws SQLException Get the execution object and put sql Send to database
// Statement: Operation static SQL sentence
Statement stmt=conn.createStatement();
// 5) Execute through the execution object sql sentence
// int executeUpdate(String sql)
int count=stmt.executeUpdate(sql);
System.out.println(" The update is successful :"+count);
// 6) Release resources
stmt.close();// Close the execution object
conn.close();// Close connection object
}
}

边栏推荐
- 软考 --- 数据库(1)数据库基础
- Group convolution
- Leetcode linked list problem -- 24. Exchange the nodes in the linked list in pairs (learn the linked list with one question and one article)
- 美司法部律师团队要求法官拒绝受理华为诉讼
- 从零开始搭建Prometheus自动监控报警系统
- 韩国计划每年砸1万亿韩元,研发半导体材料及设备
- Green and sustainable development of data center
- [ffmpeg] add timestamp summary to video files
- Shell综合应用案例,归档文件
- SprinBoot面试题
猜你喜欢
随机推荐
Buu brush inscription 2
Increased uncertainty in BTC and eth due to the approaching interest rate hike? The US economy will face more pain
[pytoch foundation] torch.stack() function analysis
Shell综合应用案例,归档文件
Common operations of ndarray in numpy
如何查看你使用的pytorch是否为GPU版本
Redis面试题
7-year-old boy playing chess too fast? The robot actually broke its finger
Houdini finds the midpoint and connects the points to form a line
CentOS7关于Oracle RAC 11GR2部署磁盘分区问题
微信支付的分账功能介绍
Beginner experience of safety testing
人脸识别、指纹识别都弱爆了?五角大楼研发远距离心跳识别
"Enterprise management" sincere crm+ - integrated management of enterprise business processes
leetcode 哈希表类
Kotlin - coroutinebuilder
Why can ThreadLocal achieve thread isolation?
Svn uses fragmented ideas
AI technology, simplifying the complex world | teatalk online application practical series, issue 2
opencv dnn部署onnx模型








![[JVM series] JVM tuning](/img/6b/f7c402b2ff5fc4f11f9656a7a59873.png)
