JAVA月考试题

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.以下选项中可以用来从表state中删除列update_dt的是( )。

A.ALTER TABLE state DROP COLUMN update_dt;

B.ALTER TABLE state DELETE COLUMN update_dt;

C.DROP COLUMN update_dt FROM state;

D. REMOVE COLUMN update_dt FROM state;

正确答案:A


2.JDBC的Connection接口不包含的方法是()。

A.createStatement()

B.prepareStatement(String sql)

C.createPrepareStatement(String sql)

mit()

正确答案:C


3.下面不属于表单属性的有()。

A.action

B.method

C.enctype
规定在发送到服务器之前应该如何对表单数据进行编码



D.size

正确答案:D


4. DTD对book元素的定义如下:



下列符合该DTD定义的XML片段是:( )。

A.

B. WhatisJava GoodMan

C. GoodManOne GoodManTwo WhatisJava

D. WhatisJava

正确答案:B


5.ResultSet提供了获取数据库中某个字段值的方法,如果某个字段为NUMBER类型,可以获取该字段值的方法是:( )。

A.getNumber()

B.getDouble()

C.setNumber()

D.setDouble()

正确答案:B


6.下列属于DML语句的是 :()。


MIT ---TCL事物控制

B.INSERT

C.DROP ---DDL数据定义语言

D.GRANT ---DCL权限控制

正确答案:B

insert/update/delete
select DQL数据查询语言


7. 在XML文档中,phone_number元素包含home或者mobile子元素,下列正确的DTD中定义方式的是:()。

A.

B.

C.

D.

正确答案:D


8.下面是某文件中XML的代码,下列选项中符合XML语法规则的是()

A. hello welcome

B. welcome

C. hello

D. Happy

正确答案:B


9.下面属于XML的实体引用的是()

A.""

B.&

C.>

D.<


正确答案:C


10.在Oracle中,现有Student表,其中包括学号stuId,姓名stuName,成绩stuGrade,现要查询成绩为80分的学生姓名,并且结果按照学号降序排列,下面查询语句正确的是()。

A.SELECT stuName FROM student WHERE stuGrade=80 ORDER BY stuId
B.SELECT stuName FROM student WHERE stuGrade=80 ORDER BY stuId DESC
C.SELECT stuName FROM student WHERE stuGradelike 80 GROUP BY stuId
D.SELECT stuName FROM student WHERE stuGrade=80 GROUP BY stuId DESC
正确答案:B


11.如果查询表a(有3行数据)和表b(有4行数据),使用SELECT * FROM a,b,返

回的查询结果的行数是:()。

A.7

B.1

C.0

D.12

正确答案:D


12. 下面XML片段,合法的是:()。

A.




B.



C.


D.
something


正确答案:C


13.在Oracle中,不能通过DROP关键字进行删除的是()。

A.表
B.视图
C.表中记录
D.序列
正确答案:C

删除表中记录用delete


14.下列不属于CSS的应用方式的是:()。

A.书写于文档头部

B.链接到外部的JavaScript文档

C.链接到外部CSS文档

D.书写于标记内部

正确答案:B


15.在JDBC中使用事务,想要回滚事务的方法是( )。

A.Connection的commit()

B.Connection的setAutoCommit()

C.Connection的rollback()

D.Connection的close()

正确答案:C


16.在JDBC连接数据库编程应用开发中,可以实现数据库连接的是()。

A.Connection接口

B.PreparedStatement类

C.CallableStatement类

D.Statement类

正确答案:A


17.DELETE和TRUNCATE都可以用来删除表内容,以下描述正确的是:()。

A.TRUNCATE不需要RollbackSegment

B.DELETE不需要RollbackSegment

C.TRUNCATE在提交COMMIT之前仍可回滚

D.TRUNCATE还可以删除表结构

正确答案:A

rollback segment是ORACLE里一种很特殊的数据对象,它处理事务的回滚操作。


18. 显示上个月的今天,这个月的今天,下个月的今天,精度到时、分、秒,下列sql语句正确的是:

A. alter session set nls_date_format = 'yyyy mm dd hh24:mi:ss';
select add_months(sysdate,-1),sysdate,add_months(sysdate,1) from dual;

B. alter user set nls_date_format = 'yyyy mm dd hh24:mi:ss';
select add_months(sysdate,-1),sysdate,add_months(sysdate,1) from dual;

C. alter session set nls_date_format = 'yyyy mm dd hh24:mi:ss';
select last_month(),this_month(),next_month() from dual;

D. alter user set nls_date_format = 'yyyy mm dd hh24:mi:ss';
select last_month(),this_month(),next_month() from dual;

正确答案:A


19.下面关于序列的描述不正确的是:()

A.序列和表一样,都是Oracle数据库中的对象

B.序列产生的值,可以作为表的主键值

C.在序列的使用中,最好的方式是多个表可以共用一个序列,来减少Oracle数据库序列的数量

D.MySql数据不支持序列

正确答案:C


20.包含事务控制方法setAutoCommit,commit, rollback的是:()。

A.Connection

B.Statement

C.ResultSet

D.DriverManager

正确答案:A


21.在HTML中,标记的size属性最大取值可以是()。

A. 5

B. 6

C. 7

D. 8

正确答案:C


22.可以在Oracle中获取当前时间的Sql语句是()

A.SELECT SYSDATE
B.SELECT SYSDATE FROM DUAL
C.SELECT DATE
D.SELECT DATE FROM DUAL
正确答案:B


23.下列选

项中能够得到字符串的一部分的单行函数是()。

A.INSERT
B.SUBSTR
C.LPAD
D.LEAST
正确答案:B


24.试图使用下面句子查询数据:SELECT 100/NVL(quantity, 0) FROMinventory;quantity为NULL空值时,将导致出错,其原因是:()。


A.除数表达式为空值.

B.函数参数数据类型不一致.

C.空值不能被转成实际值

D.除数表达式为零

正确答案:D


25. 下列关于CDATA段,书写正确的是:()。

A.

B.

C.

D.

正确答案:A


26.现有订单表(orders),包含字段:cid(顾客编号),pid(产品编号)。若查询既订购了产品P01,又订购了产品P02的顾客编号,下列Sql语句正确的是()

A.SELECT DISTINCT(cid) FROM orders o1WHERE o1.pid IN(‘p01’,’p02’)

B.SELECT DISTINCT(cid) FROM ORDERS o1,orderso2WHERE o1.pid=’p01’ AND o2.pid=’p02’AND o1.cid=o2.cid

C.SELECT DISTINCT(cid) FROM ordersWHERE pid=’p01’ AND cid IN(select cid FROM ordersWHERE pid=’p02’)

D.SELECT DISTINCT(cid) FROM orders o1,orderso2WHERE o1.pid=’p01’ AND o2.pid=’p02’

正确答案:C


27.下面关于事务(Transaction)的说法错误的是:()。

A.事务具备ACID四个基本特性,即A(Atomicity)—原子性、C(Consistency)—一致性、I(Isolation)—隔离性、D(Durability)—持久性。
B.事务的提交(Commit)指将事务中所有对数据库的更新写到磁盘上的物理数据库中去,事务正常结束。
C.事务的回滚(Rollback)指在事务运行的过程中发生了某种故障,事务不能继续进行,将事务中对数据库的所有以完成的操作全部撤消,回滚到事务开始的状态。
D.JDBC通过Connection对象控制事务,默认方式下,在执行完更改语句后需要必须要调用Connection的commit方法,对数据的更改才能生效。
正确答案:D


28. 在Oracle中,有表Person,如下:
ID Name Tel
001 Amber 1234
002 Amy 2345
003 Emily 4567
004 Eric 5678
005 Roy 6789
SELECT Tel FROM Person WHERE Name = ‘A%’;
执行以上查询,结果是:

A. 1234

B. 2345

C. 4567

D. 运行后结果是“未选定行”

正确答案:D


29.下列会自动创建索引的约束的是:()。

A.UNIQUE 、 PRIMARY KEY

B.NOT NULL

C.FOREIGN KEY

D.CHECK

正确答案:A


30.下列不属于CSS选择器的有()。

A.ID选择器

B.类选择器

C.JS选择器

D.元素选择器

正确答案:C


31.CSS这个缩写名词所代表的具体含义是:()。

A.Cascading Style Sheets

B.Creative Style Sheets

puter Style Sheets

D.Colorful Style Sheets

正确答案:A


32. 下面关于PreparedStatement说法错误的是:()。

A. PreparedStatement是Statement的子接口。

B

. 使用PreparedStatement预编译SQL可以有效的防止SQL注射。

C. PreparedStatement具有批处理执行SQL的功能。

D. PreparedStatement的setXXX方法可以用于设置预留的表名、字段名等参数。

正确答案:D


33. 操作cost表,若一个月使用了200小时,计算每种资费标准对应的最终费用是多少(考虑单位费用和基础费用为null的情况,最终费用=固定费用+超时部分×单位费用),下列sql语句正确的是:

A. select id,
nvl(base_cost,0) + (200 - nvl(base_duration,0)) * nvl(unit_cost,0) fee
from cost;

B. select id,nvl(base_cost,0) fee from cost;

C. select id,200*nvl(unit_cost,0) fee from cost;

D. select id, base_cost + (200 - base_duration)*unit_cost fee from cost;

正确答案:A
34. 下面关于XML解析,说法错误的是:()。

A. SAX解析方式的效率优于DOM的方式。

B. DOM方式在解析XML文档时,需要将整个文档全部加载到内存中。

C. 使用DOM4j组件对XML解析时,可以支持XPath查找。

D. 使用DOM的方式解析文档,只能实现对XML的读取而不能写出XML数据。

正确答案:D
35.有一个数据表usernfo,包含userid,username字段,其中userid是唯一的,username可能重复,请写一句sql查询语句,把重复的记录全部取出来。
useridusername1老王2老王3老李4老李5小张
要求返回记录集如下:
useridusername1老王2老王3老李4老李
下列Sql语句正确的是:( )。
A.SELECT* FROM userinfo WHERE username IN (SELECT username FROM userinfo GROUP BYusername)

B.SELECT* FROM userinfo WHERE username IN (SELECTDISTINCT username FROM userinfo)

C.SELECT* FROM userinfo WHERE username IN (SELECT username FROM userinfo GROUP BYusername WHERE COUNT(username)>1);

D.SELECT* FROM userinfo WHERE username IN (SELECT username FROM userinfo GROUP BYusername HAVING COUNT(username)>1);

正确答案:D
36.在Oracle中,当数据量较大时,删除表中所有数据,效率较高的是()。


A.DELETE FROM Student

B.DELETE FROM Student WHERE id>0

C.TRUNCATE table Student

D.TRUNCATE table Student WHERE id>0

正确答案:C
37. 请看下列建表语句:
create table test
(c1 number(3) constraint test_c1_pk primary key,
c2 number(2) ,
c3 number(2) ,
constraint test_c2_ck check (( c2 + c3 ) > 100 )
);
下列选项中能向test表中成功实施插入数据的插入语句是:

A. insert into test values (1,40,60);

B. insert into test values (2,41,61);

C. insert into test values (3,101,1);

D. insert into test values (4,50,51);

正确答案:BD
38. 下列语句在建表的同时在c2,c3列上创建了唯一约束,其中正确的是:

A. create table test
(c1 number constraint test_c1_pk
primary key,
c2 number constraint test_c2_uk
foreign key,
c3 number constraint test_c3_uk
foreign key);

B. create table test
(c1

number constraint test_c1_pk
primary key,
c2 number ,
c3 number ,
constraint test_c3_uk foreign key(c2,c3));


C. create table test
(c1 number constraint test_c1_pk
primary key,
c2 number ,
c3 number ,
constraint test_c3_uk unique(c2,c3));

D. create table test
(c1 number constraint test_c1_pk
primary key,
c2 number constraint test_c2_uk
unique,
c3 number constraint test_c3_uk
unique);

正确答案:CD
39. 操作account表和service表,查询申请远程登录业务的客户的数据,下列sql语句正确的是:

A. select real_name from account
where in (select account_id from service);

B. select real_name from account o
where id exists
(select 1 from service i
where o.id = i.account_id);


C. select real_name from account
where id in (select account_id from service);

D. select real_name from account o
where exists
(select 1 from service i
where o.id = i.account_id);

正确答案:CD
40. 操作account表和age_segment表,查询客户huangrong的年龄段,下列sql语句正确的是:

A. select real_name,birthdate,
from account a join age_segment s
on round((sysdate - birthdate)/365) between lowage and hiage
and real_name = 'huangrong';

B. select real_name,birthdate,
from account a left join age_segment s
on round((sysdate - birthdate)/365) between lowage and hiage
and real_name = 'huangrong';

C. select real_name,birthdate,
from account a left join age_segment s
on round((sysdate - birthdate)/365) between lowage and hiage
where real_name = 'huangrong';

D. select real_name,birthdate,
from account a left join age_segment s
on round((sysdate - birthdate)/365) between lowage and hiage

正确答案:AC
41.服务器端用户日志文件的格式如下:437100 1250524800000 1250567366000545500 1256227200000 1256240694000843600 1256745600000 1256826557000………以空格分隔的三个数据分别表示用户编号,用户登入服务器的时间(毫秒数)以及用户登出服务器的时间(毫秒数)。方法populate用于将日志文件中的数据插入到数据库的t_loginfo表中,建表的SQL如下:
drop sequencet_loginfo_seq;
create table t_loginfo ( id number(12) not null, user_id number(6) notnull, login_time number(20) notnull, logout_time number(20) notnull);
alter table t_loginfo add constraint pk_t_loginfo primary key(id);
create sequence t_loginfo_seq;
populate方法的代码如下:
public void populate(File logFile) throws Exception {
int batchSize = 1000;
代码1 BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(logFile),"utf-8"));
Connection con = null;
PreparedStatement stmt =null;
try {
con = ConnUtils.openConnection();
con.setAutoCommit(false);

代码2
String line = null;
int rows = 0;
while ((line =reader.readLine()) != null) {
代码3 String[] data=line.split(" ");
stmt.setInt(1,Integer.parseInt(data[0]));
stmt.setLong(2,Long.parseLong(data[1]));
stmt.setLong(3,Long.parseLong(data[2]));
代码4 stmt.addBatch();
if (++rows >=batchSize) {
stmt.executeBatch();
stmt.clearBatch();
rows = 0;
}
}
代码5 stmt.executeBatch();mit();
} catch (Exception e) {
con.rollback();
throw e;
} finally {
if(stmt!=null)stmt.close();
if(con!=null) con.close();
}
}
(1).程序中1处应该填入的代码是:()。
A.BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile), "utf-8"));
B.BufferedReader reader = new BufferedReader(newFileReader(newFileReader(logFile), "utf-8"));
C.BufferedReader reader = new BufferedReader(new FileReader(logFile,"utf-8"));
D.BufferedReader reader = new BufferedReader(new InputStreamReader(logFile,"utf-8"));
正确答案:A
(2).程序中2处应该填入的代码是:()。
A.stmt = con.prepareStatement("insert into t_loginfo values(t_loginfo_seq.nextval(),?,?,?)");
B.stmt = con.prepareStatement("insert into t_loginfo(user_id,login_time, logout_time)values(?,?,?)");
C.stmt = con.prepareStatement("insert into t_loginfo values(?,?,?)");
D.stmt = con.prepareStatement("insert into t_loginfo values(t_loginfo_seq.nextval,?,?,?)");
正确答案:D
(3).程序中3处应该填入的代码是:()。
A.String[] data = line.split();
B.String[] data = line.split(" ");
C.String[] data = line.parse(" ");
D.String[] data = line.parse();
正确答案:B
(4).程序中4处应该填入的代码是:()。
A.stmt.executeQuery();
B.stmt.execute();
C.stmt.executeUpdate();
D.stmt.addBatch();
正确答案:D
(5).程序中5处应该填入的代码是:()。
A.stmt.execute();mit();

B.stmt.execute();con.close();

C.stmt.executeBatch();mit();

D.stmt.executeBatch();con.close();
正确答案:C
42.有产品表Products,用于记载产品的详细信息,表结构及数据如下:
ProductID ProductName UnitPrice
1 Chai 18.00
2 Chang 19.00
3 Aniseed Syrup 10.00
4 Chef Anton's Cajun Seasoning 22.00。。。其他数据
有订单表Orders,用于记载订单的信息,表结构及数据如下:
OrderID CustomerID EmployeeID
10248 VINET 5
10249 TOMSP 6。。。其他数据
有订单详细表OrderDetails,用于记载订单的详细信息,表结构及数据如下:
OrderID ProductID UnitPrice Quantity
10248 11 14.00 12
10248 4 29.80 10
10248 72 34.80 5
10249

14 18.60 9
10249 51 42.40 40。。。其他数据
(1).现需要查询产品表中所有产品的id、价格、均价以及该产品价格与均价的差值。下列SQL语句中,正确的是()。
A.SELECT ProductId,UnitPrice,(SELECT AVG(unitprice) FROM Products) AS "均价",UnitPrice- (SELECT AVG(unitprice) FROM Products) AS "差额" FROM Products
B.SELECT ProductId,UnitPrice,(SELECT AVG(unitprice) FROM Products)AS"均价",UnitPrice- AVG(unitprice) AS “差额” FROM Products
C.SELECT ProductId,UnitPrice,AVG(unitprice) AS “均价”,UnitPrice - AVG(unitprice)AS “差额”FROM Products
D.SELECT ProductId,UnitPrice,AVG(unitprice) AS “均价”,UnitPrice - AVG(unitprice)AS “差额”FROM Products GROUP BY ProductID
正确答案:A
(2).需要查询产品表中单价最低的产品的详细信息(注意:可能会有相同价格的产品)。下列SQL语句中,正确的是()。
A.SELECT * FROMProducts ORDER BY UnitPrice WHERE ROWNUM<2
B.SELECT * FROMProducts ORDER BY UnitPrice DESC WHERE ROWNUM<2
C.SELECT * FROM Products WHERE UnitPrice = (SELECT MIN(UnitPrice)FROM Products)
D.SELECT * FROM Products WHERE UnitPrice = MIN(UnitPrice)
正确答案:C
(3).需要查询订购数量最多的前5种商品的ID及其订购总数(提示:OrderDetails表中的Quantity列表示产品的订购数量),下列SQL语句中,正确的是()。
A.SELECT ProductId,SUM(Quantity) AS "Sum" FROM OrderDetails GROUP BY ProductID HAVING ROWNUM<=5
B.SELECT ProductId,SUM(Quantity) AS "Sum" FROM orderdetails GROUP BY ProductID DESCHAVING ROWNUM<=5
C.SELECT ProductId,SUM(Quantity) AS "Sum" FROM OrderDetails GROUP BY ProductID ORDER BY SUM(Quantity) DESC WHERE ROWNUM<=5
D.SELECT * FROM (SELECT ProductId,SUM(Quantity) AS "Sum" FROM OrderDetails GROUP BY ProductID ORDER BY SUM(Quantity) DESC) WHERE ROWNUM<=5
正确答案:D
(4).需要查询产品表中,产品名称以字符串cha开头,且名称的总长度为4个字符的产品的详细数据。下列SQL语句中,正确的是()。
A.SELECT * FROM Products WHERE ProductName LIKE 'cha%'
B.SELECT * FROM Products WHERE ProductName LIKE 'cha_'
C.SELECT * FROM Products WHERE ProductName = 'cha%'
D.SELECT * FROM Products WHERE ProductName = 'cha_'
正确答案:B
(5).需要查询订单ID为10248的订单所购买的商品ID、商品名称、顾客ID以及购买数量。查询的结果如下所示:
ProductIDProductNameCustomerIDQuantity11Queso CabralesVINET1242Singaporean Hokkien Fried MeeVINET1072Mozzarella di GiovanniVINET5
下列SQL语句中,正确的是()。
A.SELECT od.ProductID,p.ProductName,o.CustomerID, od.Quantity FROM Products p JOIN OrderDetails od, Orders o WHERE P.ProductID = od.ProductID AND od.OrderID = o.OrderID and o.OrderID = 10248
B.SELECT od.ProductID,p.ProductName,o.CustomerID, od.Quantity FROM Products p JOIN OrderDetails od, Orders o ON p.ProductID = od.ProductID AND od.OrderID = o.OrderID WHERE o.OrderID =10248
C.SELECT od.P

roductID,p.ProductName,o.CustomerID, od.Quantity FROM Products p JOIN OrderDetails od ON p.ProductID= od.ProductID AND Orders o ON od.OrderID= o.OrderID WHERE o.OrderID = 10248
D.SELECT od.ProductID,p.ProductName,o.CustomerID,od.Quantity FROM Products p JOIN OrderDetails od ON p.ProductID = od.ProductID JOIN Orders o ON od.OrderID = o.OrderID WHERE o.OrderID =10248
正确答案:D