日期:2014-05-16  浏览次数:20598 次

Oracle&JDBC&Hibernate面试26问

1、JDBC连接数据库6步

1.         Loadthe JDBC Driver

2.         Establishthe Database Connection

3.         Createa Statement Object

4.         Executea Query

5.         Processthe Results

6.         Closethe 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,设置级连删除;

答案:createtable CUSTOMBERS(

                   ID bigint not null,

                   NAME varchar(15),

                   AGE int,

                   primary key (ID)

                   );

          create table ORDERS(

ID bigint not null,

ORDER_NUMBER varchar(15) not nulll,

PRICE double precision,

CUSTOMER_ID bigint,

        primary key(ID),

);

alter table ORDERS addconstraint FK_CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMERS(ID) ondelete cascade;

 

6、使用左外连接查询,ORDERS和CUSTOMERS 表,

答案:selectc.ID, o.CUSTOMER_ID,c.NAME, o.ID ORDER_ID,ORDER_NUMBER from CUSTOMERS c leftouter join ORDERS o no c.ID=o.CUSTOMER_ID;

 

7、简述数据库事务的生命周期?(可画流程图)

答案:

 

8、deletefrom tablea & truncate table tablea的区别  drop

答:truncate 语句执行速度快,占资源少,并且只记录页删除的日志;

  delete 对每条记录的删除均需要记录日志

 

9Hibernate的检索方式

答:①导航对象图检索 OID检索 HQL检索 QBC检索 本地SQL检索