OCP Java17 SE Developers 复习题15(完)

server/2024/12/22 21:50:36/

======================== 答案  ========================

=====================================================

=====================================================

B, F.  The Driver and PreparedStatement interfaces are part of the JDK, making options A and E incorrect. Option C is incorrect because we made it up. The concrete DriverManager class is also part of the JDK, making option D incorrect. Options B and F are correct since the implementation of these interfaces is part of the database-specific driver JAR file.

======================== 答案  ========================

=====================================================

=====================================================

A.  A JDBC URL has three main parts separated by single colons, making options B, C, E, and F incorrect. The first part is always jdbc, making option D incorrect. Therefore, the correct answer is option A. Notice that you can get this right even if you've never heard of the Sybase database before.

======================== 答案  ========================

=====================================================

=====================================================

B, D.  When setting parameters on a PreparedStatement, there are only options that take an index, making options C and F incorrect. The indexing starts with 1, making option A incorrect. This query has only one parameter, so option E is also incorrect. Option B is correct because it simply sets the parameter. Option D is also correct because it sets the parameter and then immediately overwrites it with the same value.

======================== 答案  ========================

=====================================================

=====================================================

C.  A Connection is created using a static method on DriverManager. It does not use a constructor. Therefore, option C is correct. If the Connection was created properly, the answer would be option B.

======================== 答案  ========================

=====================================================

=====================================================

B.  The first line has a return type of boolean, making it an execute() call. The second line returns the number of modified rows, making it an executeUpdate() call. The third line returns the results of a query, making it an executeQuery() call. Therefore, option B is the answer.

======================== 答案  ========================

=====================================================

=====================================================

B.  The first line enables autocommit mode. This is the default and means to commit immediately after each update. When the rollback() runs, there are no uncommitted statements, so there is nothing to roll back. This gives us the initial two rows in addition to the inserted one making option B correct. If setAutoCommit(false) were called, option A would be the answer. The ResultSet types are just there to mislead you. Any types are valid for executeUpdate() since no ResultSet is involved.

======================== 答案  ========================

=====================================================

=====================================================

C.  This code works as expected. It updates each of the five rows in the table and returns the number of rows updated. Therefore, option C is correct.

======================== 答案  ========================

=====================================================

=====================================================

A, B.  Option A is one of the answers because you are supposed to use braces ({}) for all SQL in a CallableStatement. Option B is the other answer because each parameter should be passed with a question mark (?). The rest of the code is correct. Note that your database might not behave the way that's described here, but you still need to know this syntax for the exam.

======================== 答案  ========================

=====================================================

=====================================================

E.  This code declares a bind variable with ? but never assigns a value to it. The compiler does not enforce bind variables have values, so the code compiles, but produces a SQLException at runtime, making option E correct.

======================== 答案  ========================

=====================================================

=====================================================

D.  JDBC code throws a SQLException, which is a checked exception. The code does not handle or declare this exception, and therefore it doesn't compile. Since the code doesn't compile, option D is correct. If the exception were handled or declared, the answer would be option C.

======================== 答案  ========================

=====================================================

=====================================================

D.  JDBC resources should be closed in the reverse order from that in which they were opened. The order for opening is ConnectionCallableStatement, and ResultSet. The order for closing is ResultSetCallableStatement, and Connection, which is option D.

======================== 答案  ========================

=====================================================

=====================================================

C.  This code calls the PreparedStatement twice. The first time, it gets the numbers greater than 3. Since there are two such numbers, it prints two lines. The second time, it gets the numbers greater than 100. There are no such numbers, so the ResultSet is empty. Two lines are printed in total, making option C correct. The ResultSet options are just there to trick you since only the default settings are used by the rest of the code.

======================== 答案  ========================

=====================================================

=====================================================

B, F.  In a ResultSet, columns are indexed starting with 1, not 0. Therefore, options A, C, and E are incorrect. There are methods to get the column as a String or Object. However, option D is incorrect because an Object cannot be assigned to a String without a cast.

======================== 答案  ========================

=====================================================

=====================================================

C.  Since an OUT parameter is used, the code should call registerOutParameter(). Since this is missing, option C is correct.

======================== 答案  ========================

=====================================================

=====================================================

C, D.  Rolling back to a point invalidates any savepoints created after it. Options A and E are incorrect because they roll back to lines 19 and 17, respectively. Option B is incorrect because you cannot roll back to the same savepoint twice. Options C and D are the answers because those savepoints were created after curly.

======================== 答案  ========================

=====================================================

=====================================================

E.  First, notice that this code uses a PreparedStatement. Options A, B, and C are incorrect because they are for a CallableStatement. Next, remember that the number of parameters must be an exact match, making option E correct. Remember that you will not be tested on SQL syntax. When you see a question that appears to be about SQL, think about what it might be trying to test you on.

======================== 答案  ========================

=====================================================

=====================================================

D.  This code calls the PreparedStatement twice. The first time, it gets the numbers greater than 3. Since there are two such numbers, it prints two lines. Since the parameter is not set between the first and second calls, the second attempt also prints two rows. Four lines are printed in total, making option D correct.

======================== 答案  ========================

=====================================================

=====================================================

D.  Before accessing data from a ResultSet, the cursor needs to be positioned. The call to rs.next() is missing from this code causing a SQLException and option D to be correct.

======================== 答案  ========================

=====================================================

=====================================================

E.  This code should call prepareStatement() instead of prepareCall() since it is not executing a stored procedure. Since we are using var, it does compile. Java will happily create a CallableStatement for you. Since this compile safety is lost, the code will not cause issues until runtime. At that point, Java will complain that you are trying to execute SQL as if it were a stored procedure, making option E correct.

======================== 答案  ========================

=====================================================

=====================================================

B.  The prepareStatement() method requires SQL to be passed in. Since this parameter is omitted, line 27 does not compile, and option B is correct.

======================== 答案  ========================

=====================================================

=====================================================

B, D.  The code starts with autocommit off. As written, we turn autocommit mode back on and immediately commit the transaction. This is option B. When line W is commented out, the update gets lost, making option D the other answer.


http://www.ppmy.cn/server/18973.html

相关文章

机器学习之sklearn基础教程

ChatGPT Scikit-learn (简称sklearn) 是一个非常受欢迎的Python机器学习库。它包含了从数据预处理到训练模型的各种工具。下面是一个关于如何使用sklearn进行机器学习的基础教程。 1. 安装和导入sklearn库 首先,你需要安装sklearn库(如果你还没有安装的…

排序算法-快速排序

一、快速排序 快速排序也属于交换排序,通过元素之间的比较和交换位置来达到排序的目的。 冒泡排序在每一轮中只把1个元素冒泡到数列的一端。而快速排序则在每一轮挑选一个基准元素,并让其他比它大的元素移动到数列一边,比它小的元素移动到数列…

[C++ QT项目实战]----C++ QT系统登陆界面设计

前言 在C QT项目开发过程中,设计系统登录界面可以使用QT框架来实现。以下是一个简单的系统登录界面设计示例: 创建登录界面UI:可以使用QT Designer来设计登录界面的UI,包括用户名输入框、密码输入框、登录按钮等。在QT Designer中…

wow-slist文件说明

wow-slist文件说明 项目地址:https://gitee.com/wow-iot/wow-iot7本文件的的功能主要用于链表相关操作,主要涉及创建、销毁、插入、查找、移除、替换、获取、清空、遍历; 创建与销毁: Slist_T* wow_slist_create(void) {Slist_T *slist C…

用 Python 创建 Voronoi 图

概述 最常见的空间问题之一是找到距离我们当前位置最近的兴趣点 (POI)。假设有人很快就会耗尽汽油,他/她需要在为时已晚之前找到最近的加油站,解决这个问题的最佳解决方案是什么?当然,驾驶员可以检查地图来找到最近的加油站&…

GEM TSU Interface Details and IEEE 1588 Support

摘要:Xilinx ZNYQ ULTRASCALE MPSOC的GEM和1588的使用 对于FPGA来说,只需要勾选一些znyq的配置就行了,其余的都是软件的工作; 所有配置都勾选之后,最终会露出来的接口如下: GEM需要勾选的配置如下&#xf…

【C++】哈希思想

目录 哈希介绍: 一,位图 1-1,位图的认识 1-2,位图的简单实现 1-3,位图的应用 二,布隆过滤器 2-1,布隆过滤器的认识 2-2,布隆过滤器的简单实现 2-3,布隆过滤器的…

Android Glide 获取动图的第一帧

一、说明 Glide 可以加载 2 种动图,一种是 Gif 图,另一种是 Webp 动图。 有时候我们需要获取动图的第一帧,并以封面的形式显示,那该怎样获取呢? 二、获取 Webp 第一帧 我这儿的 Webp 显示用到了一个三方库&#xf…