当前位置:网站首页>JDBC介绍
JDBC介绍
2022-07-06 09:25:00 【手可摘鑫晨】
1,JDBC概念
Java Database Connectivity(JDBC):Java访问数据库的解决方案。
JDBC定义了一套接口,即访问数据库的通用API,不同数据库厂商根据各自数据库的特点去实现这些接口。
JDBC希望用相同的方式访问不同的数据库,让具体的数据库操作与数据库厂商实现无关,从而在
不同数据库之间轻易的进行切换。
2,JDBC相关类接口
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/dayone?serverTimezone=GMT";
String user = "root";
String pwd = "123456";
Connection conn = DriverManager.getConnection(url, user, pwd);
String sql = "insert into student(sname,birthday,ssex,classid) values('张三','2022-1-1','男','100')";
Statement statm = conn.createStatement();
int ret = statm.executeUpdate(sql); //执行DML语句(添加,删除,修改),返回值int
//ResultSet rs = stmt.executeQuery(sql); //执行DQL语句(查询),返回值ResultSet
if(ret > 0) {
System.out.println("执行成功了");
}else {
System.out.println("执行失败了");
}
(5)释放资源
statm.close();
conn.close();
边栏推荐
- How to use Moment. JS to check whether the current time is between 2 times
- Software testing interview summary - common interview questions
- Login the system in the background, connect the database with JDBC, and do small case exercises
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- 自动化测试你必须要弄懂的问题,精品总结
- C language do while loop classic Level 2 questions
- How to solve the poor sound quality of Vos?
- Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
- With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
- Face and eye recognition based on OpenCV's own model
猜你喜欢
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
CSAPP家庭作業答案7 8 9章
Opencv recognition of face in image
Install and run tensorflow object detection API video object recognition system of Google open source
Software testing interview summary - common interview questions
[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases
ucore lab5用户进程管理 实验报告
后台登录系统,JDBC连接数据库,做小案例练习
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
随机推荐
What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
ucore lab2 物理内存管理 实验报告
Summary of thread implementation
Public key box
Cc36 different subsequences
Investment operation steps
[200 opencv routines] 98 Statistical sorting filter
数字电路基础(二)逻辑代数
[oiclass] maximum formula
pytest
Which version of MySQL does php7 work best with?
Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
王爽汇编语言学习详细笔记一:基础知识
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers
软件测试方法有哪些?带你看点不一样的东西
Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Sorting odd and even subscripts respectively for leetcode simple problem
CSAPP Shell Lab 实验报告
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set