Question

In: Computer Science

I am having a hard time with these questions regarding JDBC and XML. 1) Which type...

I am having a hard time with these questions regarding JDBC and XML.

1)

Which type of driver provides JDBC access via one or more ODBC drivers?

Group of answer choices

a) Type 1 driver

b) Type 2 driver

c) Type 3 driver

d) Type 4 driver

2)

Which of the following provides the application-to-JDBC Manager connection.

a) JDBC Driver

b) JDBC API

c) JDBC Driver API

d) SQL Server

3)

With the code below, indicate JDBC coding best practices that have been violated (this code does compile and run!):

import java.sql.*;

public class StudentData{
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(args[2], args[0], args[1]);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM Student WHERE rollno='" + args[3] + "'");

while (rs.next()) {
System.out.print(rs.getInt(1) + "\t");
System.out.print(rs.getString(2) + "\t ");
System.out.print(rs.getInt(3) + "\t ");
System.out.println(rs.getDate(4));
}
stmt.close();
stmt = null;
rs.close();
rs = null;
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}

  

a) The program imports all of the java.sql packages

b) This program does not properly close database resources

c) The program should catch SQLException

d) The program should not string-concatenate a query, but rather use a PreparedStatement.

e) The program retrieves data from a ResultSet by column number instead of by name

f) The program hardcodes the name of the JDBC driver and the SQL query. These should be externalized from the compilable code.

g) Answer 1, 3 and 5 only

h) Answers 1-6 all apply

4)

In JDBC, it is a good practice to use standard SQL statement and avoid using db specific query until necessary.

a) True

b) False

Solutions

Expert Solution

Answer)
Q1) The type of driver provides JDBC access via one or more ODBC drivers:

a) Type 1 driver

The Type 1 driver of JDBC is responsible for Java translating the JDBC interface calls to the ODBC calls.

Q2) The following provides the application-to-JDBC Manager connection.

b) JDBC API

The JDBC API gives access to the data from Java programming. Using this we can access the data sources such as traditional, relation databases and others.

Q3.

a) The program imports all of the java.sql packages -- only the required packages should be imported and not all

b) This program does not properly close database resources -- connection conn is not closed after the use

c) The program should catch SQLException -- SQLException should be caught before Generic Exception type

d) The program should not string-concatenate a query, but rather use a PreparedStatement. -- Should use the PreparedStatement rather than writing the query using string-concatenation

e) The program retrieves data from a ResultSet by column number instead of by name -- rs.getInt(1) this is confusing and could create errors while retrieving the data

f) The program hardcodes the name of the JDBC driver and the SQL query. These should be externalized from the compilable code. -- True, the program should not hardcode the database driver details and should draw these from some property file

Thus the correct answer is:
h) Answers 1-6 all apply

Q4. In JDBC, it is a good practice to use standard SQL statement and avoid using db specific query until necessary.

-- True, standard SQL statements should be sued and not db specific query as this means that we have to perform minimal changes to the Java DAO layer.


Related Solutions

I am having a hard time understanding these two questions. If someone can explain that would...
I am having a hard time understanding these two questions. If someone can explain that would be great. 1) Explain the steps that enables body to metabolize fat to ATP? 2) Write out the amount of ATP, NADH, FADH2 produced in each step of cellular metabolism of a glucose.
I understand the answer to this I am just having a hard time creating a graph...
I understand the answer to this I am just having a hard time creating a graph for it. Bill the butcher is upset because the government plans to tax beef $.10 a pound. "I hate paying taxes," he says. "Because of this, I'm raising all my beef prices by $.10 a pound. The consumers will bear this burden, not me." Do you see anything wrong with this way of thinking? Explain. Draw a graph describing your answer and attach it...
I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
I have figured out this assignment, but I am having a hard time figuring out the...
I have figured out this assignment, but I am having a hard time figuring out the extra credit, Thanks! Creating a Rectangle class We have created a representation of a rectangle in C++ and extended it to create multiple representation's of rectangles. Classes can simplify that process considerably. In this assignment, your task is to convert the representation of a rectangle we created earlier in the semester to a Rectangle class. The Rectangle class shall consist of the following: The...
can someone explain to me what osmolality is.? i am having a hard time understanding it
can someone explain to me what osmolality is.? i am having a hard time understanding it
I am having a hard time getting my an output after putting in the second set...
I am having a hard time getting my an output after putting in the second set of functions and I was hoping to be able to have the results from the functions be rounded to 2 decimal places. <html> <head> <title>Length Conversion</title> <script language='JavaScript' type='text/JavaScript'> <!-- function validate(type) { if(document.my_form.textinput.value=='') { alert('Fill the Input box before submitting'); return false; }else{ if(type=="to_feet"){ var res=3.2808*document.my_form.textinput.value; var unit=" feet"; }else{ var res=0.3048*document.my_form.textinput.value; var unit=" meter"; } document.getElementById("result").innerHTML=res.toFixed(2) + unit; return false; } }...
For some reason I am having a hard time getting this program to compile properly. Could...
For some reason I am having a hard time getting this program to compile properly. Could you help me debug it? Write the prototypes and functions to overload the given operators in the code //main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() {     rectangleType rectangle1(23, 45);                     //Line 1     rectangleType rectangle2(12, 10);                     //Line 2     rectangleType rectangle3;                             //Line 3     rectangleType rectangle4;                             //Line 4     cout << "Line...
I am having a hard time writing these SQL queries. Please specify the following queries in...
I am having a hard time writing these SQL queries. Please specify the following queries in SQL on the database schema shown in the figure below. STUDENT Name StudentNumber Class Major Smith 17 1 CS Brown 8 2 CS Kathy 15 1 EE COURSE CourseName CourseNumber CreditHours Department Intro to Computer Science CSE110 4 CS Data Structures CSE205 4 CS Discrete Mathematics MAT240 3 MATH Databases CSE380 3 CS Analog Circuits EE260 3 EE SECTION SectionIdentifier CourseNumber Semester Year Instructor...
Hello, I am having a hard time being able to fully understand how firm strategy, technology...
Hello, I am having a hard time being able to fully understand how firm strategy, technology and investment affects the emergence of the digital gaming industry? Please go into great detail.
C# programming. Comment/Explain the below code line by line. I am having a hard time following...
C# programming. Comment/Explain the below code line by line. I am having a hard time following it. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Nth_prime {     class Program     {         public static bool isPrime(int number)         {             int counter = 0;             for (int j = 2; j < number; j++)             {                 if (number % j == 0)                 {                     counter = 1;                     break;                 }             }             if (counter == 0)             {                 return true;             }             else             {                 return false;             }         }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT