JDBC 運算元據庫

2021-07-30 09:05:44 字數 826 閱讀 3804

使用jdbc技術連線資料庫的步驟

1.註冊驅動程式

class.forname("資料庫驅動的完整類名");

2.獲取乙個資料庫的連線

connection connection=drivermanager.getconnection("連線url","使用者名稱","密碼")

3.建立乙個會話

statement st=conn.createstatement();

4.執行sql語句,增刪改查

st.executequery/extcuteupdate("增刪改查的sql語句")

5.查詢的結果集

resultset set=st.executequery("........");

6.關閉連線

set.close();

st.close();

conn.close();

各個資料庫建立連線和驅動的語句。

mysql 資料連線

1.class.forname("com.mysql.jdbc.driver");

2.drivermanager.getconnection("jdbc:mysql://localhost/[database name]","user","password");

oracle(thin)資料庫連線:

1.class.forname("oracle.jdbc.driver.oracledriver");

2.drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:[database name]","scott","tiger");

JDBC運算元據庫

一.步驟 1.載入資料庫驅動 class.forname 驅動全名 2.獲取connection連線 connection con drivermanager.getconnection url 注 資料庫的版本不同url有可能不同。例 mysql 8.0 url jdbc mysql localh...

JDBC方式運算元據庫

1.讀取配置檔案,我將配置資訊寫入配置檔案 properties 中,方便後期資料庫變更後或者其他專案使用,擴充套件性好些,盡量避免硬編碼.driver oracle.jdbc.driver.oracledriver url jdbc oracle thin 127.0.0.1 1521 orcl ...

原始的Jdbc運算元據庫

載入資料庫驅動 class.forname com.mysql.jdbc.driver 通過驅動類連線資料庫 connecttion con drivermanger.getconnection jdbc mysql localhost 3306 資料庫名 使用者名稱 密碼 定義sql語句 stri...