天天看點

jdbc知識問答

1 JDBC連接配接資料庫6步

Load the JDBC Driver

Establish the Database Connection

Create a Statement Object

Execute a Query

Process the Results

Close the Connection

2 事務的4大特性

答:原子性A,一緻性C,隔離性I,永久性D

3.select count(*) from student 和select count(id) from student 之間的差別。

答案:

select count(*) 統計所有學生的記錄個數,包括空記錄。

Select count(Id) 統計所有學生的記錄個數,不包括null記錄。

4假設現在有表system.table1,表中有三個字段:id(數值型)、name(字元型)、age(數值型)寫出SQL語句完成如下功能:在表中查出年齡大于20,且名字以“王”開頭的記錄,并且按照年齡的倒叙排列出來(年齡大的在前面)。

Select * from system.table1 where age>20 and name like ‘王%’ order by age DESC;

5 .建立CUSTOMERS表,字段為:ID:(非空,主鍵)bigint,NAME:(非空)varchar,AGE:int類型;建立ORDERS表,字段為:ID:(非空,主鍵,)bigint,ORDER_NUMBER:(非空)varchar,PRICE:double,CUSTOMER_ID :(外鍵)bigint,設定級連删除;

答案:create table CUSTOMBERS(

ID bigint not null,

NAME varchar(15),

AGE int,

primary key (ID)

);

create table ORDERS(

ORDER_NUMBER varchar(15) not nulll,

PRICE double precision,

CUSTOMER_ID bigint,

primary key(ID),

alter table ORDERS add constraint FK_CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMERS(ID) on delete cascade;

6.使用左外連接配接查詢,ORDERS 和 CUSTOMERS 表,

答案:select c.ID, o.CUSTOMER_ID,c.NAME, o.ID ORDER_ID,ORDER_NUMBER from CUSTOMERS c left outer join ORDERS o no c.ID=o.CUSTOMER_ID;

29 .簡述資料庫事務的生命周期?(可畫流程圖)

7.delete from tablea & truncate table tablea的差別

   truncate 語句執行速度快,占資源少,并且隻記錄頁删除的日志;

   delete 對每條記錄的删除均需要記錄日志

本文轉自linzheng 51CTO部落格,原文連結:http://blog.51cto.com/linzheng/1080793