package com.workingdogs.town;import java.sql.*;import java.util.*;/*Town, a Java JDBC abstraction layerCopyright (C) 1999 Serge Knystautas, Jon S. StevensThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Library General PublicLicense as published by the Free Software Foundation; eitherversion 2 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULibrary General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with this library; if not, write to theFree Software Foundation, Inc., 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.*//**This class is used for doing SQL select statements on the database. Itshould not be used for doing modifications via update/delete/insert statements.If you would like to perform those functions, please use aTableDataSet.Here is some example code for using a QueryDataSet.QueryDataSet qds = new QueryDataSet ( connection, "SELECT * from my_table" );qds.fetchRecords(10); // fetch only the first 10 recordsfor ( int i = 0; i < qds.size(); i++ ){ Record rec = qds.getRecord(i); int value = rec.getValue("column").asInt(); System.out.println ( "The value is: " + value );}qds.close();It is important to always remember to close() a QueryDataSet in order tofree the allocated resources.@author Jon S. Stevens jon@working-dogs.com@author Serge Knystautas sergek@lokitech.com@version 1.0*/public class QueryDataSet extends DataSet{ protected String selectString; /** * Creates a new QueryDataSet based on a connection and a select string * * @param conn * @param selectStmt * @exception ConnectionException * @exception DataSetException */ public QueryDataSet(String driver, String connString, String selectStmt) throws ConnectionException, DataSetException { this (driver, connString, null, null, selectStmt); } /** * Creates a new QueryDataSet based on a connection and a select string * * @param conn * @param selectStmt * @exception ConnectionException * @exception DataSetException */ public QueryDataSet(String driver, String connString, String username, String password, String selectStmt) throws ConnectionException, DataSetException { super (driver, connString, username, password); try { //this.conn = conn; //if (! (selectStmt.startsWith ("select") || // selectStmt.startsWith ("SELECT"))) // throw new DataSetException ("QueryDataSet must be a SELECT string"); selectString = selectStmt; stmt = dbconn.createStatement(); resultSet = stmt.executeQuery (selectStmt); schema = new Schema(); schema.populate (resultSet.getMetaData()); } catch (SQLException sqle) { throw new ConnectionException (sqle); } } /** * This method was created in VisualAge. */ public Record addRecord () throws ConnectionException, DataSetException { throw new DataSetException ("Cannot add a record to a QueryDataSet"); } /** * Return the KeyDef for this dataset * @return com.workingdogs.town.KeyDef */ public KeyDef getKeyDef () throws DataSetException { throw new DataSetException ("QueryDataSet does not support a KeyDef for now."); } /** * get the Select String that was used to create this QueryDataSet * * @return a select string */ protected String getSelectString () throws ConnectionException, DataSetException { return selectString; } /** Gets the tableName upon table data set creation @return string */ public String getTableName() throws DataSetException, ConnectionException { throw new DataSetException ("QueryDataSet does not support table names now."); }}