JDBC技術(shù)是java程序和底層數(shù)據(jù)庫之間架起的橋梁,可以實(shí)現(xiàn)對(duì)底層數(shù)據(jù)庫的增刪改查基本功能和其他功能,今天我們來看看它的增刪改查功能。
一.基本操作
1.查看所有存在的數(shù)據(jù)庫
show databases;
2.新建一個(gè)數(shù)據(jù)庫
create database testdb;
3.使用testdb數(shù)據(jù)庫,每次使用數(shù)據(jù)庫時(shí)必須要選擇所使用的數(shù)據(jù)庫
use testdb;
4.查看當(dāng)前數(shù)據(jù)庫中所有表
show tables;
5.新建表
create table person(id int(11) primary key not null auto_increment,name varchar(20) not null,age int(11));
6.查看當(dāng)前數(shù)據(jù)庫版本,當(dāng)前日期
select verson(),current_date;
7.描述pet表結(jié)構(gòu)
describe pet;
8.向person表中插入數(shù)據(jù)
insert into person(name,age) values('zhangsan',32);
9.person表查詢記錄
select * from person where name='rose';
10.修改person表中某條記錄
update person set name ='lady gaga',age=44 where id=3;
11.刪除person中某條記錄
delete from person where id = 4;
12.導(dǎo)入數(shù)據(jù)庫文件
source E:\jdbc_db.sql;
二.jdbc編程步驟
1.加載數(shù)據(jù)庫驅(qū)動(dòng)(jar文件)
2.獲得數(shù)據(jù)庫連接
3.創(chuàng)建語句(SQL)
4.執(zhí)行查詢
5.遍歷結(jié)果集
6.關(guān)閉數(shù)據(jù)庫連接
下一篇博客我會(huì)用一個(gè)基于數(shù)據(jù)庫存儲(chǔ)的學(xué)生系統(tǒng),用它來演示JDBC操作,敬請(qǐng)期待。