JDBC Flashcards

1
Q

relational database

A

a database that is organized into tables, which consist of rows and columns

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

What do you have to know about SQL for the exam?

A

Pretty much nothing.

Just assume any SQL code that you see is valid.

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

Driver interface

A

Knows how to get a connection to the database

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

Connection interface

A

Knows how to communicate with the database

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

Statement interface

A

Knows how to run the SQL

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

ResultSet interface

A

Knows what was returned by a SELECT query

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

JDBC URL format

A

jdbc:database_name:connection_details

The first part is jdbc. The second part is the name of the vendor/ product. The third part varies by database, but it includes the location and name of the database. The location is either localhost or an IP address followed by an optional port.

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

How to create a Connection using DriverManager

A

DriverManager.getConnection(jdbc_url)

DriverManager.getConnection(
jdbc_url, “username”,
“password”);

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

How to create a Statement from a Connection called conn

A

conn. createStatement()

conn. (ResultSet, ResultSet)

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

What modes is a ResultSet in by default?

A

TYPE_FORWARD_ONLY and CONCUR_READ_ONLY

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

ResultSet.TYPE_FORWARD_ONLY

A

You can go through the data once in the order in which it was retrieved.

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

ResultSet.TYPE_SCROLL_INSENSITIVE

A

Allows you to go through the data in any order. You can go both forward and backward. You can even go to a specific spot in the data.

Note: there is another value TYPE_SCROLL_SENSITIVE that most databases don’t support.

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

ResultSet.CONCUR_READ_ONLY

A

It means that you can’t update the result set.

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

ResultSet.CONCUR_UPDATABLE

A

lets you modify the database through the ResultSet

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

What method do you use to execute a SQL statement given Statement stmt?

A

For UPDATE, DELETE, and INSERT:

stmt.executeUpdate(sql_statement);

Returns the number of rows that were inserted, deleted, or changed.

For SELECT:

stmt.executeQuery(sql_statement);

Returns a ResultSet

For general use:

stmt.execute(sql_statement)

Returns a boolean that indicates whether or not it is a ResultSet

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

How to loop through a ResultSet

A

while(rs.next())

17
Q

When talking about row/column numbers in JDBC, we start with 1, NOT 0

A

Just remember that

When talking about row/column numbers in JDBC, we start with 1, NOT 0

18
Q

Given type scroll insensitive ResultSet rs

rs.absolute(n)

A

Moves to the row number n. Returns a boolean saying if there is data in this row.

**Remember that rows start counting with 1

Note: A negative number means to start counting from the end of the ResultSet rather than from the beginning.

19
Q

Given type scroll insensitive ResultSet rs

rs.relative(n)

A

Moves n rows from the current row.

20
Q

What should you do once you are done with your Connections and Statements and ResultSets?

A

Close em, dude!

Or open them up in a try-with-resources statement to make them close automatically.

21
Q

JDBC automatically closes a ResultSet when…

A

you run another SQL statement from the same Statement.

22
Q

Order to close the JDBC components

A

ResultSet
Statement
Connection

23
Q

SQLException methods

getMessage()

getSQLState()

getErrorCode()

A
  • returns a human-readable message as to what went wrong
  • returns a code as to what went wrong
  • returns a database-specific code