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 />

while (scanner.hasNext()) {<br />

sql.append(scanner.nextLine());<br />

sql.append("\n");<br />

}<br />

scanner.close();<br />

stream.close();<br />

Connection connection = null;<br />

Statement statement = null;<br />

try {<br />

connection = dataSource.getConnection();<br />

statement = connection.createStatement();<br />

statement.execute(sql.toString());<br />

} catch (SQLException ex) {<br />

ex.printStackTrace();<br />

throw new RuntimeException(ex);<br />

} finally {<br />

if (null != connection) {<br />

try {<br />

connection.close();<br />

} catch (SQLException ex) {<br />

}<br />

}<br />

}<br />

stream = data.getInputStream();<br />

scanner = new Scanner(stream);<br />

sql = new StringBuilder();<br />

while (scanner.hasNext()) {<br />

sql.append(scanner.nextLine());<br />

sql.append("\n");<br />

}<br />

scanner.close();<br />

stream.close();<br />

connection = null;<br />

statement = null;<br />

try {<br />

connection = dataSource.getConnection();<br />

statement = connection.createStatement();<br />

statement.executeUpdate(sql.toString());<br />

} catch (SQLException ex) {<br />

ex.printStackTrace();<br />

throw new RuntimeException(ex);<br />

} finally {<br />

if (null != connection) {<br />

try {<br />

connection.close();<br />

} catch (SQLException ex) {<br />

}<br />

}<br />

}<br />

123

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

Saved successfully!

Ooh no, something went wrong!