Database Connectivity - DAO Flashcards

1
Q

JDBC

A

Java Database Connectivity

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

Java Database Connectivity

A

a library that allows Java applications to access SQL databases in a standard way.

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

Spring JDBC

A

a framework that provides an abstraction for JDBC making it easier to use,
provides a consistent way to create queries, handle results, deal with exception, and automatically provides transactions

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

Connection Pool

A

makes multiple connections to the database and keeps them open. When an application needs a connection it “checks one out” from the pool. When it is finished with it, it returns it to be reused

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

Connection String

A

like an address (URL) to a web site only used to connect to a database.It includes details on what vendor driver to use, where the database is located on a network, the name of the database to connect to, and the credentials (user id / password)

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

Making a Connection

A

BasicDataSource dvdstoreDataSource = new BasicDataSource();
dvdstoreDataSource.setUrl(“jdbc:postgresql://localhost:5432/dvdstore”);
dvdstoreDataSource.setUsername(“postgres”);
dvdstoreDataSource.setPassword(“postgres1”);

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

BasicDataSource

A

The org.apache.commons.dbcp2.BasicDataSource provides the ability to make a database connection and a Connection Pool.

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

The setUrl takes a connection string as an argument:

A

jdbc:postgresql://localhost:5432/dvdstore
jdbc:postgresql:// tells the DataSource to use JDBC with the PostgreSQL Vendor Driver
localhost:5432 tells the DataSource the location of the database on a network, in this case the same computer.
dvdstore is the name of the database which to connect

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

setUsername() and setPassword()

A

methods set the username and password to use when connecting to the database

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

JDBCTemplate allows for the execution of queries using the DataSource.

A

JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);

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

Queries that return results, like SELECT, use

A

jdbcTemplate.queryForRowSet(sql, params1…paramsN)

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

Queries that do not return results, like INSERT, UPDATE, and DELETE, use

A

jdbcTemplate.update(sql, params1…paramsN)

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

Parameters

A

values used in a query should not be concatenated, unless the source of the value is a known as safe.

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

DAO Pattern

A

Data Access Object (DAO)

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

Data Access Object (DAO)

A

design pattern encapsulates the details of persistent storage inside of classes whose only role is to store and retrieve data

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

DAOs usually perform CRUD operations on domain objects (also called Business Objects).

A

Create
Read
Update
Delete

17
Q

DAO pattern makes code loosely coupled

A

solating data access code inside of DAOs decouples the rest of the application from the details of persistence
Relational databases are often used for persistent storage, but other technologies could be used such as the filesystem, NoSQL database, web service, etc
Isolates the code changes that need to be made in the event of a table schema change.

18
Q

Parts of the DAO Pattern

A

The DAO Pattern breaks the responsibility of data access into 3 parts.
Data Object
DAO Interface
Implementation Class (JDBCDao)

19
Q

Data Object

A

a simple data object (POJO) often called a domain or business object. This data object will act as a data type that represents on row of data returned by the queries. It often matches the columns of the table being accessed.

20
Q

DAO Interface

A

An interface that defines methods for the CRUD operations that the implementation class must provide. These methods will generally use either the DAO Domain Object or simple types (String, long, int, etc) as return types and arguments.

21
Q

Implementation Class (JDBCDao)

A

will implement the DAO Interface, take a DataSource as a constructor argument, and encapsulate the interactivity with the data source.