16.10.2015 Views

Getting Started with WebSphere Application Server

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

82 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> Community Edition<br />

Connection con = null;<br />

Statement stmt = null;<br />

try {<br />

Context initContext = new InitialContext();<br />

DataSource ds =<br />

(DataSource)initContext.lookup("java:comp/env/jdbc/DataSource");<br />

// Get a database connection<br />

con = ds.getConnection();<br />

} catch(java.lang.Exception e) {<br />

e.printStackTrace();<br />

System.err.print(e.getClass().getName());<br />

System.err.println(e.getMessage());<br />

}<br />

try {<br />

// Prepare a statement object used to execute query<br />

stmt = con.createStatement();<br />

String sql = "SELECT empID, empName FROM employees " +<br />

"WHERE XMLEXISTS('$i/employee[age > \"25\"]' PASSING empDOC AS \"i\")";<br />

// Fill returned data into ResultSet object.<br />

ResultSet rs = stmt.executeQuery(sql);<br />

%><br />

The employees who are older than 25 years old are:<br />

<br />

<br />

<br />

Employee ID<br />

Employee Name<br />

<br />

<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!