//============================================================================== // FakeResultSet.java //============================================================================== package tribble.sql.test; import java.math.BigDecimal; import java.net.URL; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import tribble.sql.ResultSetAdapter; /******************************************************************************* * Fake JDBC result set driver class. * * *
*
Source code:
*
Available at: * http://david.tribble.com/src/java/tribble/sql/test/FakeResultSet.java *
*
Documentation:
*
Available at: * http://david.tribble.com/docs/tribble/sql/test/FakeResultSet.html *
*
* * @version @(#)$Revision: 1.3 $ $Date: 2008/09/06 18:42:15 $ * @since 2008-09-02 * @author David R. Tribble (david@tribble.com) *

* Copyright ©2008 by David R. Tribble, all rights reserved.
* Permission is granted to any person or entity except those designated by * by the United States Department of State as a terrorist, or terrorist * government or agency, to use and distribute this source code provided * that the original copyright notice remains present and unaltered. * * @see Test1 * @see FakeStatement */ class FakeResultSet extends tribble.sql.ResultSetAdapter { static final String REV = "@(#)tribble/sql/test/FakeResultSet.java $Revision: 1.3 $ $Date: 2008/09/06 18:42:15 $\n"; // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Constants private static final String[][] NAMES = { { "Shane", "Austin" }, { "Bobby", "Brown" }, { "Bobby", "Finnique" }, { "Wilma", "Jones" }, { "Alan", "McBride" }, { "Austin", "Powers" }, { "George", "Reeves" }, { "Sharon", "Stone" }, { "Zack", "Weaver" }, { "Lemma", "Zime" }, }; private static final int MAX_ROWS = NAMES.length; // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Variables private String m_stmt; private int m_nRows; private long m_now = (new java.util.Date()).getTime(); // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Constructors /*************************************************************************** * Constructor. * * @since 1.1, 2008-09-02 */ FakeResultSet(String stmt) { m_stmt = stmt; } // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Methods public boolean next() { m_nRows++; return (m_nRows <= MAX_ROWS); } public boolean wasNull() { return false; } public boolean getBoolean(int col) { return true; } public int getInt(int col) { return m_nRows; } public String getString(int col) throws SQLException { switch (col) { case 2: return NAMES[m_nRows-1][0]; case 3: return NAMES[m_nRows-1][1]; } throw new SQLException("Access beyond the end of data"); } public Date getDate(int col) { return new Date(m_now); } public Time getTime(int col) { return new Time(m_now); } public Timestamp getTimestamp(int col) { return new Timestamp(m_now); } public Object getObject(int col) { return "Hello[" + m_nRows + "]"; } } // End FakeResultSet.java