JDBC Flashcards

0
Q

The JDBC classes are part of the packages java.sql.* and javax.sql.*?

A

Yes

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

JDBC 4.1 introduces RowSet and its related utility classes such as RowSetFactory and RowSetProvider?

A

Yes

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

Connection interface of the java.sql package represents a connection from application to the database?

A

Yes

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

You can get a connection object by invoking the DriverManager.getConnection() method; the method expects the URL of the database along with a database name, user name, and password?

A

Yes

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

Prior to JDBC 4.0, you would have to explicitly load the JDBC driver using the Class.forName() statement, as in the following: Class.forName(“com.mysql.jdbc.Driver”).newInstance(); Connection connection = DriverManager.getConnection(url + database, userName, password)

A

Yes

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

JDBC provides two important interfaces to support queries: Statement and Resultset.

A

Yes

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

Statement comes in three flavors: Statement, PreparedStatement, and CallableStatement

A

Yes

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

when you need to send a SQL statement to the database without any parameter. In normal cases, you need to use…

A

Statement

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

You can create an instance of Statement using…

A

…createStatement() method in the Connection interface

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

a precompiled SQL statement that can be customized using IN parameters. Usually, it is more efficient than a Statement object; hence, it is used to improve the performance, especially if a SQL statement is executed multiple times…

A

PreparedStatement

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

You can get an instance of PreparedStatement by calling the…

A

preparedStatement() method in the Connection interface.

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

used to execute stored procedures…

A

CallableStatement

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

to get an instance of CallableStatement…

A

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
13
Q

If your SQL statement is a SELECT query, you can use the … method, which returns a ResultSet

A

executeQuery()

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

When you want to update a database using one of the INSERT, UPDATE, or DELETE statements, you should use the…() method, which returns an integer reflecting the updated number of rows

A

executeUpdate()

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

If you don’t know the type of SQL statement, you can use the…() method, which may return multiple resultsets or multiple update counts or a combination of both

16
Q

ResultSet is a table with column headings and associated values requested by the query…

17
Q

column index starts from …

A

1, not from 0

18
Q

always call updateRow() after modifying the row contents; otherwise you will lose the changes

19
Q

You can get the metadata from a Connection object to examine the capabilities of the underlying database. You can do this by calling the …

A

getMetaData() method in the Connection interface

20
Q

The boolean absolute(int) method in ResultSet moves the cursor to the passed row number in that ResultSet object

21
Q

The boolean absolute(int) method if the row number is negative,

A

…it moves to that position from the end of the ResultSet object. Assume that there are 10 entries in the ResultSet object. Calling absolute(3) will move the cursor to the third row. Calling absolute(−3) will move the cursor to the 10–3, seventh row. If you give out of range values, the cursor will move to either beginning or end

22
Q

In a ResultSet object, calling absolute(1) is equivalent to calling first(), and calling absolute(−1) is equivalent to calling last

23
Q

Atomicity…

A

Each transaction should be carried out in its entirety; if one part of the transaction fails, then the whole transaction fails

24
Q

Consistency:

A

Consistency: The database should be in a valid state before and after the performed transaction

25
Q

Isolation

A

Isolation: Each transaction should execute in complete isolation without knowing the existence of other transactions

26
Q

Durability:

A

Once the transaction is complete, the changes made by the transaction are permanent (even in the occurrence of unusual events such as power loss

27
Q

Transaction-Related Methods in the Connection Interface…

A
void setAutoCommit(boolean autoCommit) 
boolean getAutoCommit() 
Savepoint setSavepoint() 
Savepoint setSavepoint(String name) 
void releaseSavepoint(Savepoint savepoint) 
void rollback(Savepoint savepoint) 
void rollback() void commit
28
Q

You can use column name or column index with ResultSet methods…

A

Yes The index you use is the index of the ResultSet object, not the column number in the database table

29
Q

It is your responsibility to issue a correct SQL command…

A

Yes…a JDBC Statement will not check for its correctness. For example, if there is a syntax error in the SQL command string, then you will not get a compiler error. Rather, you’ll get a MySQLSyntaxErrorException at runtime