当前位置:网站首页>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
}
}

边栏推荐
- [experiment sharing] CCIE BGP routing black hole experiment]
- opencv dnn部署onnx模型
- 传惠普/戴尔/微软/亚马逊考虑将部分硬件生产线转到大陆以外
- What is the role of cache in the storage system of data blocks?
- [pytorch advanced] preservation and use of pytorch model
- Houdini notes 2
- 没有网络怎么配置传奇SF登陆器自动读取列表
- 英国德国相继推出5G商用服务,华为成幕后功臣
- Buu brush inscription 2
- 详细图解b树及C语言实现
猜你喜欢

JDBC的连接

QT基础第一天 (1)QT,GUI(图形用户接口)开发

消息队列——引入的问题:重复消费&顺序消费&分布式事务

ST表、带权并查集
![[experiment sharing] CCIE BGP routing black hole experiment]](/img/c8/7ccb879ad7c739d3573637fd14f4e1.png)
[experiment sharing] CCIE BGP routing black hole experiment]

SSM integration example

Beginner experience of safety testing
![[OBS] solve the problem of OBS pushing two RTMP streams + timestamp](/img/71/dbd00f69251b96b0e56de399103f72.png)
[OBS] solve the problem of OBS pushing two RTMP streams + timestamp

Shell综合应用案例,归档文件

"Enterprise management" sincere crm+ - integrated management of enterprise business processes
随机推荐
Beginner experience of safety testing
Bean injection and lifecycle
Confid+etcd to realize automatic discovery of high availability
Svn uses fragmented ideas
08_ UE4 advanced_ Start end pause menu UI
SprinBoot面试题
What is the role of cache in the storage system of data blocks?
JDBC的引入
Shell comprehensive application cases, archive files
serializable接口的作用是什么?
How to check whether the pytorch you are using is a GPU version
易基因|宏病毒组测序技术介绍
Auto. JS rotation Icon
详细图解b树及C语言实现
腾讯为什么没能造创造出《原神》这样的游戏
Can the training software test be employed
Increased uncertainty in BTC and eth due to the approaching interest rate hike? The US economy will face more pain
09_ue4进阶_进入下一关并保留血量
MPLS multi protocol label switching technology
What is the function of the serializable interface?