OCP Java17 SE Developers 复习题15(完)

devtools/2024/9/20 3:55:37/ 标签: ocp, java

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

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

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

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/devtools/18306.html

相关文章

GPT产业 行业研究报告合集整理

整理了一下目前现有的与GPT产业相关的研究报告合集,帮助大家深入地分析GPT产业的技术发展情况、判断GPT产业的未来发展趋势。 下载方式:关注、私信留言获取。或查看主页文章《常用的行业研究报告免费下载来源》,在研报之家下载。 报告数量&…

可视化+多人协同技术原理和案例分享

前言 hi,大家好,我是徐小夕,之前和大家分享了很多可视化低代码的技术实践,最近也做了一款非常有意思的文档搭建引擎——Nocode/Doc: 也做了一些分享: Nocode/Doc,可视化 零代码打造下一代文件编…

RAG原理及本地化实践

基于LLM的应用在问题回答、信息获取上发挥出了巨大作用。这些通用大模型训练的数据主要来源于互联网上的会话或者个别机构提供的数据,虽然能够提供类似人的交互对答,但是在针对某个特定领域的时候就显得不足。通用大模型在应用中主要有以下问题&#xff…

Jammy@Jetson Orin - Tensorflow Keras Get Started

JammyJetson Orin - Tensorflow & Keras Get Started 1. 源由2. 步骤3. 预期&展望4. 总结5. 参考资料 1. 源由 之前过年的时候,花了两周的时间过了一遍 《ubuntu22.04laptop OpenCV Get Started》。 后续更多的时间需要再GPU算法上下功夫,目前…

【面试题】s += 1 和 s = s + 1的区别

文章目录 1.问题2.发现过程3.解析 1.问题 以下两个程序真的完全等同吗? short s 0; s 1; short s 0; s s 1; 2.发现过程 初看s 1 和 s s 1好像是等价的,没有什么区别。很长一段时间内我也是这么觉得,因为当时学习c语言的时候教科书…

Servlet(写一个Hello Worldt)【一】

文章目录 一、Servlet 目的 ----- 实现动态页面二、编写一个 Servlet 的Hello World2.1 创建项目2.2 处理文件夹2.3 引入依赖2.4 手动创建一些必要的目录/文件2.5 编写代码2.6 打包程序2.7 部署2.8 验证程序是否能正常工作 一、Servlet 目的 ----- 实现动态页面 静态页面 VS 动…

小程序变更主体还要重新备案吗?

小程序迁移变更主体有什么作用?小程序迁移变更主体的作用可不止变更主体这一个哦!还可以解决一些历史遗留问题,比如小程序申请时主体不准确,或者主体发生合并、分立或业务调整等情况。这样一来,账号在认证或年审时就不…

Android EditText 的 属性android:digits 限制输入的字符

在android开发中,在某些场景中,需要限制用户输入的字符; 比如输入电话号码,只能输入数字,输入IPV4只能输入数字和“.”,IPV6只能输入数字字符和“:”,等等。 在Android EditText输…

第十五届蓝桥杯C/C++B组题解

第十五届蓝桥杯大赛软件类省赛C/C大学B组 赛题链接A握手问题B小球反弹C好数DR格式E宝石组合F数字接龙G爬山H拔河

【GlobalMapper精品教程】074:从Lidar点云创建3D地形模型

本文基于地形点云数据,基于泊松方法、贪婪三角形测量方法和阿尔法形状创建3d地形模型。 文章目录 一、加载地形点云数据二、创建三维地形模型1. 泊松方法2. 贪婪三角形测量方法3. 阿尔法形状注意事项一、加载地形点云数据 加载配套案例数据包中的data074.rar中的地形点云数据…

NumPy 1.26 中文官方指南(四)

附加文件 术语表 原文:numpy.org/doc/1.26/glossary.html (n,) 括号中跟着逗号的数字表示一个具有一个元素的元组。尾随逗号将一个元素元组与括号n区分开。 -1 在维度入口中,指示 NumPy 选择长度,以保持数组元素总数不变。 >>> n…

OpenHarmony实战开发-按钮 (Button)

Button是按钮组件,通常用于响应用户的点击操作,其类型包括胶囊按钮、圆形按钮、普通按钮。Button做为容器使用时可以通过添加子组件实现包含文字、图片等元素的按钮。具体用法请参考Button。 创建按钮 Button通过调用接口来创建,接口调用有…

9.Godot数组|遍历|静态变量|对象|调试

数组和字典的遍历 数组的概念 数组是一组数据的集合。在程序中负责批量处理数据。数组中的元素可以包括各个类型的数据,也可以对数组内数据类型进行限定。可以通过 数组名【数字】 的形式来访问数组元素,数字 0 代表数组的第一个元素。数组可以通过调用…

Vue 3新特性解析

Vue 3是Vue.js框架的最新版本,带来了一些重要的新特性和改进。以下是Vue 3的一些新特性解析: Composition API:Vue 3引入了Composition API,它提供了一种新的组织和重用组件逻辑的方式。通过Composition API,可以将相关…

Spring AOP

AOP即 Aspect Oriented Programming 面向切面编程。 切面指的是某一类特定的问题,面向切面编程即解决某一类问题,例如前面我们介绍的拦截器,统一数据返回,统一异常处理。 AOP 是一种思想,它的实现方法有很多&#xf…

Python项目开发实战:怎么实现端口扫描器

注意:本文的下载教程,与以下文章的思路有相同点,也有不同点,最终目标只是让读者从多维度去熟练掌握本知识点。 下载教程:Python项目开发实战_端口扫描器的实现_编程案例解析实例详解课程教程.pdf 1、步骤 在Python项目开发中,设计并实现一个端口扫描器是一项基础且实用的…

K8s: 在Pod中将configmap数据注入容器

configMap 概述 文档: https://kubernetes.io/zh-cn/docs/concepts/configuration/configmap/ Kubernetes 为我们提供了 ConfigMap,可以方便的配置一些变量 是一个存储键值对 key-value 对象的 创建一个可以包含多个键值对的 ConfigMap, 以下是:mul-c…

【JavaEE多线程】线程中断 interrupt()

系列文章目录 🌈座右铭🌈:人的一生这么长、你凭什么用短短的几年去衡量自己的一生! 💕个人主页:清灵白羽 漾情天殇_计算机底层原理,深度解析C,自顶向下看Java-CSDN博客 ❤️相关文章❤️:清灵白羽 漾情天…

Guitar Pro怎么循环某个段落 Guitar Pro怎么调整吉他谱段落间距

在学习音乐的过程中,不断地重复听和练习是提高技能的关键。对于吉他手来说,利用专业的乐谱软件如Guitar Pro可以极大地辅助练习,尤其是在需要反复播放某个段落时。下面来看看Guitar Pro怎么循环某个段落,Guitar Pro怎么调整吉他谱…

内网pth横向渗透思路笔记

PTH 是 Pass the hash, 哈希传递攻击 的缩写。其原理是通过直接找到与账户相关的密码 Hash 值(通常是 NTML Hash),由于域环境中,域管理员与本地管理员的账户大概率都是相同的,利用这种场景,使用…