JDBC:Java Database Cinnectivity
是一門在java語言中用于訪問數(shù)據(jù)庫的技術(shù),同時(shí)也是JAVA訪問數(shù)據(jù)庫的標(biāo)準(zhǔn),JAVA提供了使用JAVA訪問所有數(shù)據(jù)庫的統(tǒng)一操作界面施符。
JDBC的編碼步驟:
1)薄霜,加載驅(qū)動(dòng)程序
2),創(chuàng)建連接
Connection getConnection(String url,String user,String password);
3)员魏,發(fā)送SQL語句并執(zhí)行
Statement:表示語句對(duì)象
int excuteUpdate(String sql);
用來發(fā)送insert吼肥,update录平,delete語句,返回
影響數(shù)據(jù)庫表的記錄數(shù)
ResultSet executeQuery(String sql);
用來發(fā)送select語句缀皱,返回結(jié)果集
4)斗这,關(guān)閉連接
數(shù)據(jù)庫軟件同時(shí)支持的連接數(shù)是有限的,每一個(gè)連接都占用這數(shù)據(jù)庫有限的資源唆鸡,開啟連接涝影,程序執(zhí)行結(jié)束之后必須及時(shí)師范資源枣察,關(guān)閉連接争占。
close();關(guān)閉語句對(duì)象,關(guān)閉連接對(duì)象
使用JDBC實(shí)現(xiàn)添加序目,刪除臂痕,修改數(shù)據(jù):
*使用JDBC刪除指定id值的記錄:
sql:delete from gundam id = rx78;
*修改指定賬號(hào)的密碼:
sql:update gundam set password = 'abc';
where username = 'gundam0w0';
使用JDBC實(shí)現(xiàn)查詢:
select number,kind from gundam where id = rx78;
API:
DriverManager:類,驅(qū)動(dòng)管理器
Connection getConnection(url,user,password);
Connection:連接對(duì)象
Statement createStatement();
Statement:語句對(duì)象接口
int executeUpdate(String sql);
發(fā)送增刪改SQL語句
ResultSet executeQuery(String sql);發(fā)送查新SQL語句
ResultSet:結(jié)果集對(duì)象
JdbcUtil:管理連接