java 获取dataset_querydataset.java 源代码在线查看 - Town是一个100% 纯Java API 资源下载 虫虫电子下载站...

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."); }}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值