Week 3 Flashcards

1
Q

Put these in order

establish connection
close connection
create statement and its query
execute the statement
process results & metadata

A

establish connection
create statement and its query
execute the statement
process results & metadata
close connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

You import DriverManager into your class, getConnection() does what? What does it throw?

A

getConnection() creates instances of Connection, throws SQLException and SQLTimeoutException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

T/F - getConnection() can be overloaded

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 String arguments used for getConnection?

A

Connection string (like a url), userid, password

note: connection string can specify options

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

jdbc:mysql
jdbc:oracle
jdbc:db2
jdbc:postgresql
jdbc:derby
jdbc:sqlserver
jdbc:sybase

What are these examples of?

A

Connection strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Whats the problem with hard-coding our DB details like this? What is the solution?

“static final String DATABASE_URL =
“jdbc:mysql://localhost:3306/books”;
Connection connection = null;
connection = DriverManager.getConnection(
DATABASE_URL, “CST8288”, “CST8288”)

A

It creates maintenance issues later. Solution is to use a properties class.

Note: “CST8288” is used as the username and password in the last Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where is the JDBC driver located? What is the method you can use if it is not autoloaded?

A

mysql-connector-java.jar

Class.forName(“mysql-connector-java.jar”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

T/F - DataSource and DataManager are the same

A

False. DataSource uses JNDI (Java Naming & Directory Interface) to look up the data source info

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

DataSource requires a ____ serverq but we will not use DS in this course

A

JNDI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Once we have a Connection instance we use ____________() to obtain an instance of statement.

A

createStatement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can createStatement be overloaded? How many arguments does the common form have?

A

Yes, 0 args

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does PreparedStatement differ from Statement?

A

It’s a very similar (object), it just uses parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name this: Used to invoke a stored procedure in the DB

A

CallableStatement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Once you have an instance of Statement you can call methods on it to perform SQL actions. ________() is used for SELECT and returns ResultSet, ___________() is used for INSERT, UPDATE< DELETE

A

ExecuteQuery()
ExecuteUpdate()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Both ExecuteQuery() and ExecuteUpdate() are overloaded. In their simplest form they use a single _____ _______.

A

String argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you get ResultSetMetaData?

A

Use getMetaData() with an instance of ResultSet

17
Q

With ResultSetMetaData, how did we obtain the count of columns, name of columns, and data type of columns?

A

Used getters on the instance of ResultSetMetaData

18
Q

When using ResultSetMetaData, how do the column numbers differ from arrays?

A

Column numbers start at 1.

19
Q

What method is used on a ResultSet instance to loop through each instance by row? Can hasNext() be used?

A

.next(). No.

20
Q

When you use .next() on a ResultSet instance for the first time, which is the first row that will be selected? Why?

A

Row #1. The “cursor” is placed before the first row.

21
Q

T/F - ResultSet can only retrieve rows going forward.

A

False, it can retrieve them in either direction.

22
Q

T/F - When ResultSet is changed it can change the underlying database immediately

A

True. This must be set using createStatement()

23
Q

Name this: Specifies that a ResultSet’s cursor can only move in the forward direction

A

TYPE_FORWARD_ONLY

24
Q

Name this: Specifies that ResultSet’s cursor can scroll in either direction and that the changes made to the underlying data during ResultSet processing are not reflected in the ResultSet unless the program queries the DB again.

A

TYPE_SCROLL_INSENSITIVE

25
Q

Specifies that a ResultSet’s cursor can scroll in either direction and that the changes made to teh underlying data during ResultSet processing are reflected immediately in the Result-Set

A

TYPE_SCROLL_SENSITIVE

26
Q

Specifies that a ResultSet can’t be updated–changes so the ResultSet contents cannot be reflected in the DB with ResultSet’s update methods

A

CONCUR_READ_ONLY

27
Q

Specifies that a ResultSet can be updated (i.e. changes so its contents can be reflected in the DB with ResultSet’s update methods)

A

CONCUR_UPDATABLE

28
Q

When closing our connections for the DB objects, which order is used?

A

ResultSet, Statement, Connection (Opposite of allocation order)

29
Q

What is the order that resources are allocated for DB objects?

A

Connection, Statement, ResultSet

30
Q

The Properties class is a subclass of ________, it stores a key along with a value (both are limited to type ______)

A

HashTable, String

31
Q

With the Properties class how can I get and set? How can I read from a file? How can I write to a file?

A

getProperty(), setProperty()

load()

list()

32
Q

What do we store in the Properties class?

A

JDBC connetion string, userid, pass