26-JDBC Flashcards

1
Q

What is the basic exception if there’s anything wrong with JDBC?

A

SQLException

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

Arguments in JdbcTemplate.query to query and map row to the entity?

A

JdbcTemplate.query(String, RowMapper)

T RowMapper.mapRow(ResultSet, int row) throws SQL Exception {}

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

How to create JdbcTemplate?

A

new JdbcTemplate(DataSource)

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

Can JdbcTemplate be shared among threads?

A

Yes, it’s thread-safe

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

Using JdbcTemplate to count the number of users?

A

jdbcTemplate.queryForObject(“…”, Integer.class)

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

Using JdbcTemplate to update age by user-id

A

jdbcTemplate.update(“UPDATE … age = ? WHERE id = ?”, age, id)

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

JdbcTemplate.queryForList vs. JdbcTemplate.queryForMap

A

queryForMap: expecting a single row
queryForList: expecting multiple rows, each is a Map

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

What exception does the RowMapper.mapRow for JdbcTemplate.query returns?

A

SQLException

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

With JdbcTemplate, how to handle the result set manually?

A

jdbcTemplate.query(String, ResultSetExtractor)

ResultSetExtractor.extracData(ResultSet) throws SQLException, DataAccessException

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

JdbcTemplate: RowCallbackHandler vs. RowMapper

A

RowCallbackHandler.processRow(ResultSet) won’t return record (i.e. return void)
RowMapper.mapRow(ResultSet, row) returns record

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

What kind of exception does Spring throw?

A

Spring always throws Runtime (unchecked) Exceptions

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

What exception class does Spring create to replace SQLException?

A

DataAccessException
+ Hides whether you are using JPA, Hibernate, JDBC …
+ Consistent across all supported Data Access technologies

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