⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 querydataset.java

📁 Town是一个100% 纯Java API
💻 JAVA
字号:
package com.workingdogs.town;

import java.sql.*;
import java.util.*;

/*
Town, a Java JDBC abstraction layer
Copyright (C) 1999  Serge Knystautas, Jon S. Stevens

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 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 of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free 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. It
should not be used for doing modifications via update/delete/insert statements.
If you would like to perform those functions, please use a
<a href="TableDataSet.html">TableDataSet</a>.
<P>
Here is some example code for using a QueryDataSet.
<PRE>
QueryDataSet qds = new QueryDataSet ( connection, "SELECT * from my_table" );
qds.fetchRecords(10); // fetch only the first 10 records
for ( 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();
</PRE>

It is important to always remember to close() a QueryDataSet in order to
free the allocated resources.


@author Jon S. Stevens <A HREF="mailto:jon@working-dogs.com">jon@working-dogs.com</A>
@author Serge Knystautas <a href="mailto:sergek@lokitech.com">sergek@lokitech.com</a>
@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.");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -