25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />

Listing 9-4 shows new elements used in JDBC, so let’s talk about them.<br />

• You added a DataSource class. It provides all the necessary information to connect to a<br />

database engine like username, password, driver, and URL.<br />

• You added a Connection class. It establishes a connection to the database, in this case to the<br />

HSQLDB engine.<br />

• You added a Statement class. With this class you can create all SQL related calls (INSERT,<br />

DELETE, UPDATE, SELECT).<br />

• You added a ResultSet class. It will return the result of the executed query.<br />

You can see that the DataSource is being injected, so you need to provide all the information about the database<br />

you are going to use. Listing 9-5 shows the XML configuration that holds your bean definitions.<br />

Listing 9-5. mydocuments-jdbc-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

In Listing 9-5, you got rid of the whole bean definitions. Finally! The <strong>Spring</strong> <strong>Framework</strong> provides a manager<br />

(DriverManagerDataSource class) for the DataSource that will be injected in the DocumentDAO implementation. Also,<br />

you can see that you are using the namespace (as a property holder) to use a jdbc.properties file<br />

(see Listing 9-6).<br />

118

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!