当前位置:网站首页>JDBC的连接
JDBC的连接
2022-07-26 20:00:00 【Camellia——】
package com.lin.jdbc_01;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/*
* JDBC基本入门使用
* 1)加载驱动
* 2)获取数据库连接对象
* 3)准备sql语句
* 4)获取执行对象
* 5)执行对象sql语句
* 6)返回结果
* 7)释放
* */
public class JDBCDemo {
public static void main(String[] args) throws Exception {
// 1)加载数据库驱动:com.mysql.jdbc:驱动类底层实现的是sun公司Driver接口
Class.forName("com.mysql.jdbc.Driver");
// 2)获取数据库连接对象
/*
public static Connection getConnection
(String url,String user,String password)throws SQLException
参数1:url:连接数据库的url地址(统一资源定位符)"jdbc:mysql://localhost:3306/数据库名"
参数2:连接数据库的用户名root
参数3:连接数据库的密码
*/
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb_02", "root", "123456");
// 3)准备好sql语句
String sql="update emp set salary=salary+500 where id=6;";
// 4)通过数据库连接对象获取执行对象
// Statement createStatement()throws SQLException 获取执行对象并将sql发送到数据库
// Statement:操作静态SQL语句
Statement stmt=conn.createStatement();
// 5)通过执行对象执行sql语句
// int executeUpdate(String sql)
int count=stmt.executeUpdate(sql);
System.out.println("更新成功:"+count);
// 6)释放资源
stmt.close();//关闭执行对象
conn.close();//关闭连接对象
}
}

边栏推荐
- BGP -- Border Gateway Protocol
- 「企业管理」精诚CRM+——一体化管理企业业务流程
- Bean注入和生命周期
- NVIDIA canvas first experience~
- 【问题篇】将集合[‘‘,‘‘]处理成(‘‘,‘‘)
- Depthwiseseparableconvolution: depthwise convolution and pointwise convolution
- 拦截器、、
- Ape tutoring's technological hard power: let AI start from reading children's homework
- The 50 Smartest Companies in the world announced that Chinese manufacturers account for nearly half, and Huawei ranks first
- 从零开始搭建etcd分布式存储系统+Web管理界面
猜你喜欢

Buu brush inscription 2

Buu brush inscription 3

How to assemble a registry?

BGP routing black hole and anti ring

Leetcode-300 longest increasing subsequence
![Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]](/img/f8/e6991852547a370f4363a2b763e52e.png)
Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]

St table, weighted and search set
![[interview brush 101] dynamic planning 1](/img/aa/cf9326d0a4363e96f4e2f1c6079c13.png)
[interview brush 101] dynamic planning 1

NVIDIA Canvas 初体验~

Bean注入和生命周期
随机推荐
Robin Lee was "poured cold water" enthusiasm! Baidu allied with Huawei Kirin to release "Honghu" chip
执行上下文与词法环境
李彦宏遭“泼冷水”热情不减!百度结盟华为麒麟,发布“鸿鹄”芯片
BGP的基本配置和聚合
BGP routing black hole and anti ring
Common operations of ndarray in numpy
【微信小程序】零基础学 | 小程序语法
QT signal and slot connection (loose coupling)
Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]
[Delphi] different platform descriptions of borderstyles of FMX form
South Korea plans to spend 1 trillion won a year on research and development of semiconductor materials and equipment
2022 pole technology communication - anmou technology opens a new chapter of commercialization
Bean注入和生命周期
Green and sustainable development of data center
【【实验分享】CCIE—BGP路由黑洞实验】
BGP--边界网关协议
BUU刷题记3
The lawyer team of the US Department of justice asked the judge to refuse to accept Huawei's lawsuit
Leetcode-300 longest increasing subsequence
解决IBGP的水平分割和BGP选路原则