JDBC Flashcards

1
Q

What is the purpose of the driver manager?

A

it works as a directory of JDBC drivers - it maintains a list of available data source and their drivers. The driver manager chooses an appropriate driver to communicate with the respective DBMS.

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

What is the general format of the JDBC URL?

A

jdbc: :

ie. jdbc:mysql://localhost:3306

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

What is the DriverManager used for?

A

helps establish the connection between the program (the user) and the JDBC drivers

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

What is the difference between Statement, PreparedStatement and CallableStatement?

A

Statement: Sends a SQL statement to the database without any parameters. For typical uses, you need to use this interface. You can create an instance of Statement using the createStatement() method in the Connection interface

PreparedStatement: Represents a precompiled SQL statement that can be customized using IN parameters. You can get an instance of PreparedStatement by calling the preparedStatement() method in the Connection interface

CallableStatement: Executes stored procedures. CallableStatement instances can handle IN as well as OUT and INOUT parameters. You need to call the prepareCall() method in the Connection interface to get an instance of this class

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

What does a executeQuery() method returns?

A

returns a ResultSet

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

What does a executeUpdate() method returns?

A

returns an update count

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

What does a execute() method returns?

A

multiple ResultResets or multiple update counts or a combination of both

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

What is the column index that the resultSet starts from?

A

1

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

What are the two ways of updating the database?

A

queries or you can fetch a resultset using SQL query and then change the database

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

What are the key interfaces of JDBC?

A
  • Driver ( knows how to get a connection from the database)
  • Connection (knows how to communicate with the database)
  • Statement (knows how to run the SQL)
  • Result (knows what was returned by the select query)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the two ways of getting a connection?

A

DriverManager or DataSource

DriverManager.getConnection(“jdbc:derby:zoo”)

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

How to obtain a statement?

A

stmt = conn.createStatement()

or

stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY

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

What are the ResultSet Type options?

A

ResultSetType : Can go backwards : See latest data

  • ResultSet.TYPE_FORWARD_ONLY : no : no
  • ResultSet.TYPE_SCROLL_INSENSITIVE: yes : no
  • ResultSet_TYPE_SCROLL_SENSITIVE : yes : yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the ResultSet ConcurrencyMode?

A

ResultSetType : can read data : can update data

  • ResultSet.CONCUR_READ_ONLY : yes : no
  • ResultSet.CONCUR_UPDATABLE: yes : yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you execute a statement?

A

Statement stmt = conn.createStatement()

int result = stmt.executeUpdate( “insert/update/delete”

or

ResultSet rs = stmt.executeQuery(“select * from species”);

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

True or false

execute() can only execute queries

A

False

execute() can run either a query or an update

17
Q

True or false

Closing a connection does not close the statement and ResultSet

A

false

Closing a connection also closes statement and resultSet

18
Q

True or false

closing a statement also closes the ResultSet

A

true

19
Q

True or false

JDBC automatically closes a ResultSet when you run another SqlStatement

A

true

20
Q

Which are the required parts of a jdbc url?

A

jdbc and database name

21
Q

What file is required inside a jdbc 4.0+ drier jar?

A

META-INF/service/java.sql.Driver

22
Q

Which ones return boolean and which ones return void?

absolute(int)
relative(int)
previous()

afterLast()
beforeFirst()

A

boolean:

absolute(int)
relative(int)
previous()

void:

afterLast()
beforeFirst()

23
Q

What is the difference between PreparedStatement and CallableStatement?

A

A PreparedStatement is used for SQL statements that are executed multiple times with different values.

A CallableStatement is meant for executing a stored procedure, which has already been created in the database.

24
Q

What SQL standard must a JDBC compliant driver implement?

A

SQL92