簡單的資料庫處理

2021-04-08 18:55:40 字數 1244 閱讀 5340

1.對資料庫表查詢處理

string id="1";  connection con=getconnection();//getconnection();是連線資料庫

[1] string sql="selcet * from wenxian where id=?";

preparedstatement prepstmt=con.preparestatement(sql);

prepstmt.setstring(1,id);

resultset rs=prepstmt.executequery();

[2] string sql="select * from wenxian where id='"+id+"'";

statement stmt=con.createstatement();

resultset rs=stmt.executequery(sql);

[3] //查詢前10條記錄 按時間倒排

string sql="select top 10 * from wenxian order by date desc";

2.對資料庫表刪除處理

string sql="delete from wenxian where id='"+id+"'";

statement stmt=con.createstatement();

stmt.executeupdate(sql);

3.對資料庫表的新增處理

string id="1";string name="yihuei";string tetcont="nihao";

[1] string sql="insert into wenxian(id,name,tetcont) values(?,?,?)";

preparedstatement prepstmt=con.preparestatement(sql);

prepstmt.setstring(1,id);

prepstmt.setstring(2,name);

prepstmt.setstring(3,tetcont);

prepstmt.executequery();

[2] string sql="insert into wenxian(id,name,tetcont) values('"+id+"','"+name+"','"+tetcont+"')";

statement stmt=con.createstatement();

stmt.executeupdate(sql); 

簡單使用資料庫資料庫

查詢 註釋 查詢公式 select 欄位名字1 別名,欄位名字2 as 別名.from 表名 執行順序 from select確定結果集 查詢dept表中的所有資訊 select from dept 查詢僱員表中所有員工的員工編號,員工姓名,上級編號 要查詢的資料 empno,ename,mgr 條...

資料庫(七)資料庫分頁處理

資料分頁處理的方式有 1 客戶端 應用程式或瀏覽器 分頁 2 應用伺服器分頁 list list executequery select from employee order by id int count list.size list sublist list.sublist 10,20 優點 ...

資料庫壞塊的處理

當 oracle 資料庫出現壞塊時,oracle 會在警告日誌檔案 alert sid.log 中記錄壞塊的資訊 ora 01578 oracle data block corrupted file 7,block ora 01110 data file oracle1 oradata v920 o...

資料庫表的處理

1 修改表的欄位 約束 修改欄位名 change alter table table name change 原始名字 新欄位名 型別 約束 修改欄位的型別 約束 modify alter table table name modify 欄位名 型別 約束 增加欄位 add alter table ...

資料庫 資料庫簡單操作語法

1.create 建立 建立資料庫 create database 資料庫名稱 建立資料庫指定字符集 create database 資料庫名稱 character set 字符集名 2.retrieve 查詢 查詢所有資料庫的名稱 show databases 3.update 修改 修改資料庫字...