com.mockrunner.example.jdbc.OrderDB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.jdbc;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This example calls a stored procedure that returns all the names
* for a specified date.
*/
public class OrderDB
{
public static List getNames(Date date) throws SQLException
{
Connection connection = DriverManager.getConnection("jdbc:db2://127.0.0.1/test");
CallableStatement statement = connection.prepareCall("call getnames(?)");
statement.setDate(1, date);
ResultSet result = statement.executeQuery();
List resultList = new ArrayList();
while(result.next())
{
resultList.add(result.getString("name"));
}
result.close();
statement.close();
connection.close();
return resultList;
}
}