//============================================================================== // Test1.java //============================================================================== package tribble.sql.test; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import tribble.sql.SqlObjectQuery; import tribble.sql.SqlObjectResultSet; /******************************************************************************* * Test driver for class {@link tribble.sql.SqlObjectQuery SqlObjectQuery}. * * *
*
Source code:
*
Available at: * http://david.tribble.com/src/java/tribble/sql/test/Test1.java *
*
Documentation:
*
Available at: * http://david.tribble.com/docs/tribble/sql/test/Test1.html *
*
* * @version @(#)$Revision: 1.4 $ $Date: 2008/09/06 18:41:45 $ * @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 SqlObjectQuery * @see SqlObjectResultSet */ public class Test1 { static final String REV = "@(#)tribble/sql/test/Test1.java $Revision: 1.4 $ $Date: 2008/09/06 18:41:45 $\n"; // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Static methods /*************************************************************************** * Test driver for class {@link SqlObjectQuery}. * * @since 1.1, 2008-09-02 */ public static void main(String[] args) throws Exception { Connection conn = null; Statement stmt = null; SqlObjectResultSet res = null; SqlObjectQuery query = null; try { // Build an SQL query query = new SqlObjectQuery(EmployeeInfo.class); query.addField("e.employee_id", "m_id"); query.addField("e.first_name", "setFirstName()"); query.addField("e.last_name", "setLastName()"); query.addField("ei.hire_date", "setHireDate()"); query.addClause("from employees e"); query.addClause("join employee_info ei"); query.addClause(" on ei.employee_id = e.employee_id"); query.addClause("where ei.hire_date >= '{d 2008-01-01}'"); // Perform the SQL query conn = new FakeConnection(); stmt = conn.createStatement(); res = query.executeQuery(stmt); // Retrieve and display the query results for (int n = 1; res.next(); n++) { EmployeeInfo info; // Retrieve the next row from the query result info = (EmployeeInfo) res.getResult(); // Display the row object System.out.println("[" + n + "]"); info.print(System.out); } } finally { // Clean up if (query != null) query.close(); if (stmt != null) stmt.close(); } } } // End Test1.java