01: package com.mockrunner.example.jdbc;
02:
03: import java.sql.CallableStatement;
04: import java.sql.Connection;
05: import java.sql.Date;
06: import java.sql.DriverManager;
07: import java.sql.ResultSet;
08: import java.sql.SQLException;
09: import java.util.ArrayList;
10: import java.util.List;
11:
12: /**
13: * This example calls a stored procedure that returns all the names
14: * for a specified date.
15: */
16: public class OrderDB {
17: public static List getNames(Date date) throws SQLException {
18: Connection connection = DriverManager
19: .getConnection("jdbc:db2://127.0.0.1/test");
20: CallableStatement statement = connection
21: .prepareCall("call getnames(?)");
22: statement.setDate(1, date);
23: ResultSet result = statement.executeQuery();
24: List resultList = new ArrayList();
25: while (result.next()) {
26: resultList.add(result.getString("name"));
27: }
28: result.close();
29: statement.close();
30: connection.close();
31: return resultList;
32: }
33: }
|