当前位置:网站首页>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();//关闭连接对象
}
}

边栏推荐
- 884. Uncommon words in two sentences - hash table
- 让华为吃了败诉的CNEX Labs到底有何来头?
- What functions does the medical live broadcast platform need
- serializable接口的作用是什么?
- 884. 两句话中的不常见单词-哈希表
- The lawyer team of the US Department of justice asked the judge to refuse to accept Huawei's lawsuit
- opencv dnn部署onnx模型
- TinUI发展历程
- [Delphi] different platform descriptions of borderstyles of FMX form
- Do employees have to compensate the company for losses when they resign? The 34 year old captain resigned and was claimed 10.66 million yuan by the company
猜你喜欢

81.(cesium之家)cesium修改灰色背景(默认蓝色)

解决IBGP的水平分割和BGP选路原则

分组卷积(Group Converlution)

Establishment of APP automation testing framework (VIII) -- establishment of ATX server2 multi device cluster environment

每日练习------有一组学员的成绩,将它们按降序排列,要增加一个学员的成绩,将它插入成绩序列,并保持降序
![Installation and configuration of [basic services] [database] Clickhouse](/img/fe/5c24e4c3dc17a6a96985e4fe97024e.png)
Installation and configuration of [basic services] [database] Clickhouse

Marketing and sales document management and workflow solutions

08_ue4进阶_开始结束暂停菜单等ui

BGP的基本配置和聚合

BGP--边界网关协议
随机推荐
09_ue4进阶_进入下一关并保留血量
2022 pole technology communication - anmou technology opens a new chapter of commercialization
It is said that HP / Dell / Microsoft / Amazon are considering transferring some hardware production lines outside the mainland
Keepalived high availability introduction and configuration details
[基础服务] [数据库] ClickHouse的安装和配置
全球最聪明50家公司公布:中国厂商占据近半,华为名列第一
Installation and configuration of [basic services] [database] Clickhouse
传惠普/戴尔/微软/亚马逊考虑将部分硬件生产线转到大陆以外
20220726
Buu brush inscription 3
单核A7玩转人脸识别,恩智浦“跨界处理器”又玩出新花样!
BUU刷题记1
【Delphi】FMX Form的BorderStyles不同平台说明
数据块的存储系统中缓存的作用是什么?
Swiftui 4's new function of real-time access to click location.Ontapgeture {location in} (tutorial with source code)
创建一个自身类的静态对象变量,究竟会如何执行?
【面试必刷101】动态规划1
serializable接口的作用是什么?
【PyQt5基本控件使用解析】
NVIDIA Canvas 初体验~