MyEclipce運算元據庫

2021-07-23 17:10:47 字數 1401 閱讀 3916

1、首先獲取連線connection,這樣myeclipce才知道連線到哪個資料庫

由於dao中已經建立連線的方法,這樣直接呼叫dao包下dbconnection 中的getconnection方法獲取連線

**展示:

dbconnection dbc;

connection conn;

在構造方法中例項化dbc;conn=dbc.getconnection;

2、已經連上資料庫這時則需要對資料庫進行操作;

在講這一點之前,我們來回顧一下資料庫語言有哪些:

1、建立表:create table tablename(列名1 資料型別 primary key,列名2 資料型別);

autocrement自動增長

2、插入資料:insert into tablename values(列1值 ,列2值);

insert into tablename (列1,列3) values(列1值,列3值);

3、查詢資料:select * from tablename 查詢tablename全表

select * from tablename where id=? 查詢tablename表中id=?

select * from tablename where id=? and price=?查詢tablename表中的id=?同時price=?的值

4、修改資料:update tablename set 列名=修改後的資料 where 列名=修改前的資料

5、刪除表中資料:delete from tablename刪除表中全部內容

drop tablename刪除表

delete from tablename where id=?;刪除id=?那一行

講過資料庫操作基本語言,那接下來來談談怎麼在myeclipce中使用這些語言來運算元據庫了

這時我們需要使用到preparedstatement預載入語句   

使用方法呢:直接上**了(我這邊是測試**,遍歷新增20條資料的)

for(int i=0;i<20;i++) catch (sqlexception e)

}         注意:插入中文時需要使用' '修飾;

3、通過以上**,我們可以發現preparedstatement只是用於執行資料庫語句的工具,所以重點還是資料庫語句的使用

resultset的使用,廢話不多說**附上:

public arraylistgetgroup()

} catch (sqlexception e)

return list;

}       resultset可以暫時儲存查詢到的資料

附帶update操作**:

public void updata(arraylistarray) catch (sqlexception e) }}

運算元據庫

python importmysqldb defmydbtest conn mysqldb.connect host localhost user root passwd sa db b4img charset utf8 cursor conn.cursor sql select from imag...

運算元據庫

2.localhost 的位址 檢視 一般位於c windows system32 driver etc下,一般在最後有這麼一行 127.0.0.1 localhost 資料庫操作方法 鏈結資料庫 建立資料庫表 資料庫插入操作 資料庫查詢操作 後記 try 使用 fetchone 方法獲取一條資料 ...

運算元據庫

是選擇乙個 是可選引數 新建資料庫 create if not exists db name default character set charset name 檢視當前伺服器下的資料庫列表 show like pattern where expr 檢視警告資訊 show warnings 修改資...