當前位置: 首頁>>代碼示例>>Java>>正文


Java ResultSetHandler類代碼示例

本文整理匯總了Java中org.apache.commons.dbutils.ResultSetHandler的典型用法代碼示例。如果您正苦於以下問題:Java ResultSetHandler類的具體用法?Java ResultSetHandler怎麽用?Java ResultSetHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResultSetHandler類屬於org.apache.commons.dbutils包,在下文中一共展示了ResultSetHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public static void main(String[] args) throws SQLException {

		final String url = "jdbc:h2:./target/test;AUTO_SERVER=TRUE";
		final String driver = "org.h2.Driver";
		final String usr = "sa";
		final String pwd = "";

		QueryRunner run = new QueryRunner();

		DbUtils.loadDriver(driver);
		Connection conn = DriverManager.getConnection(url, usr, pwd);
		// -----------------------------------------------------------------------------------
		ResultSetHandler<Employee> resultHandler = new BeanHandler<Employee>(
				Employee.class);

		try {
			Employee emp = run.query(conn,
					"SELECT * FROM employee WHERE employeename=?",
					resultHandler, "Jose");
			System.out.println(emp.getEmployeeId());
		} finally {
			DbUtils.close(conn);
		}

	}
 
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:26,代碼來源:BeanHandlerExample.java

示例2: createInsertHandler

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
/**
 * 創建插入類型ResultSetHandler
 */
public static <T> ResultSetHandler<T> createInsertHandler() {
    ResultSetHandler<T> rsh = new ResultSetHandler<T>() {

        @Override
        @SuppressWarnings("unchecked")
        public T handle(ResultSet rs) throws SQLException {
            if (rs.next()) {
                return (T) rs.getObject(1);
            }
            return null;
        }
    };

    return rsh;
}
 
開發者ID:huhuics,項目名稱:tauren,代碼行數:19,代碼來源:ResultSetHandlerFactory.java

示例3: selectCountBySql

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public static int selectCountBySql(String countSql) {
	Connection conn=getConnection();
	QueryRunner runner=new QueryRunner();
	ResultSetHandler<Integer> rsh=new ResultSetHandler<Integer>() {
		@Override
		public Integer handle(ResultSet rs) throws SQLException {
			while (rs.next()) {
				return rs.getInt(1);
			}
			return 1;
		}
	};
	int count=0;
	try {
		count=runner.query(conn,countSql, rsh);
	} catch (SQLException e) {
		e.printStackTrace();
	}
	return count;
}
 
開發者ID:dbiir,項目名稱:ts-benchmark,代碼行數:21,代碼來源:BizDBUtils.java

示例4: selectSingleBySql

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public static double selectSingleBySql(String avgSql) {
	Connection conn=getConnection();
	QueryRunner runner=new QueryRunner();
	ResultSetHandler<Double> rsh=new ResultSetHandler<Double>() {
		@Override
		public Double handle(ResultSet rs) throws SQLException {
			while (rs.next()) {
				return rs.getDouble(1);
			}
			return 0.0;
		}
	};
	Double avg=0.0;
	try {
		avg=runner.query(conn,avgSql, rsh);
	} catch (SQLException e) {
		e.printStackTrace();
	}
	if(avg==null) avg=0.0;
	return avg;
}
 
開發者ID:dbiir,項目名稱:ts-benchmark,代碼行數:22,代碼來源:BizDBUtils.java

示例5: query

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public <T> T query(Connection conn, String sql, ResultSetHandler<T> resultSetHandler) {
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        statement = conn.createStatement();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing query on {}: {}", displayConnection(conn), sql);
        }
        resultSet = statement.executeQuery(sql);
        return resultSetHandler.handle(resultSet);
    } catch (SQLException e) {
        throw new DataAccessException(e);
    } finally {
        DbUtils.closeQuietly(resultSet);
        DbUtils.closeQuietly(statement);
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:18,代碼來源:JdbcHelper.java

示例6: loadTriggers

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
@Override
public List<Trigger> loadTriggers() throws TriggerLoaderException {
  logger.info("Loading all triggers from db.");
  Connection connection = getConnection();

  QueryRunner runner = new QueryRunner();
  ResultSetHandler<List<Trigger>> handler = new TriggerResultHandler();

  List<Trigger> triggers;

  try {
    triggers = runner.query(connection, GET_ALL_TRIGGERS, handler);
  } catch (SQLException e) {
    logger.error(GET_ALL_TRIGGERS + " failed.");

    throw new TriggerLoaderException("Loading triggers from db failed. ", e);
  } finally {
    DbUtils.closeQuietly(connection);
  }

  logger.info("Loaded " + triggers.size() + " triggers.");

  return triggers;
}
 
開發者ID:JasonBian,項目名稱:azkaban,代碼行數:25,代碼來源:JdbcTriggerLoader.java

示例7: getScoreData

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public IRScoreData getScoreData(String hash, int mode) {
	IRScoreData result = null;
	try {
		ResultSetHandler<List<IRScoreData>> rh = new BeanListHandler<IRScoreData>(IRScoreData.class);
		List<IRScoreData> score;
		score = qr.query("SELECT * FROM score WHERE sha256 = '" + hash + "' AND mode = " + mode, rh);
		if (score.size() > 0) {
			IRScoreData sc = null;
			for (IRScoreData s : score) {
				if (sc == null || s.getClear() > sc.getClear()) {
					sc = s;
				}
			}
			result = sc;
		}
	} catch (Exception e) {
		Logger.getGlobal().severe("スコア取得時の例外:" + e.getMessage());
	}
	return result;
}
 
開發者ID:exch-bms2,項目名稱:beatoraja,代碼行數:21,代碼來源:ScoreDatabaseAccessor.java

示例8: getScoreDatas

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
/**
 * プレイヤースコアデータを取得する
 * 
 * @param hashes
 *            スコアを取得する楽曲のhash
 * @return <ハッシュ, スコアデータ>のマップ
 */
public Map<String, IRScoreData> getScoreDatas(String[] hashes, int mode) {
	Map<String, IRScoreData> result = new HashMap<String, IRScoreData>();
	try {
		ResultSetHandler<List<IRScoreData>> rh = new BeanListHandler<IRScoreData>(IRScoreData.class);
		StringBuilder str = new StringBuilder();
		for (String hash : hashes) {
			if (str.length() > 0) {
				str.append(',');
			}
			str.append('\'').append(hash).append('\'');
		}

		List<IRScoreData> scores = qr
				.query("SELECT * FROM score WHERE sha256 IN (" + str.toString() + ") AND mode = " + mode, rh);
		for (IRScoreData score : scores) {
			result.put(score.getSha256(), score);
		}
	} catch (Exception e) {
		Logger.getGlobal().severe("スコア取得時の例外:" + e.getMessage());
	}
	return result;
}
 
開發者ID:exch-bms2,項目名稱:beatoraja,代碼行數:30,代碼來源:ScoreDatabaseAccessor.java

示例9: executeMultipleInserts

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
/**
 *
 * @param database
 * @param sqlList
 * @param parametersList
 * @return
 */
public static List<Long> executeMultipleInserts(MetadataDatabase database, List<String> sqlList, List<Object[]> parametersList) {
    try (Connection conn = database.getConnection()) {
        List<Long> results = new ArrayList<>();
        for (int i = 0; i < sqlList.size(); i++) {
            Object[] parameters = parametersList.get(i);
            String sql = sqlList.get(i);
            
            ResultSetHandler<Long> rsh = new ScalarHandler<>();
            Long id = queryRunner.insert(conn, sql, rsh, parameters);
            results.add(id);
        }
        return results;
    } catch (SQLException e) {
        throw new JVoidDataAccessException(e);
    }
}
 
開發者ID:jVoid,項目名稱:jVoid,代碼行數:24,代碼來源:DbUtils.java

示例10: find

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
/**
 * Return the lock identified by the given identifier.
 */
public JobLock find(String id) throws SQLException {

    ResultSetHandler<JobLock> rsh = new ResultSetHandler<JobLock>() {
        @Override
        public JobLock handle(ResultSet rs) throws SQLException {

            if (!rs.next()) {
                return new JobLock();

            } else {
                JobLock lock = new JobLock();
                lock.setLocked(true);
                Timestamp expiresAt = rs.getTimestamp(2);
                lock.setExpiresAt(expiresAt.getTime());
                return lock;
            }
        }
    };

    return queryExecutor.query("select id,expires_at from sched_job_locks where id=?", rsh, id);
}
 
開發者ID:AirVantage,項目名稱:av-sched,代碼行數:25,代碼來源:JobLockDao.java

示例11: findAll

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
/**
 * Return all the existing locks grouped by their identifier.
 */
public Map<String, JobLock> findAll() throws SQLException {

    ResultSetHandler<Map<String, JobLock>> rsh = new ResultSetHandler<Map<String, JobLock>>() {
        @Override
        public Map<String, JobLock> handle(ResultSet rs) throws SQLException {

            Map<String, JobLock> map = new HashMap<String, JobLock>();

            while (rs.next()) {
                JobLock lock = new JobLock();
                lock.setLocked(true);
                String id = rs.getString(1);
                Timestamp expiresAt = rs.getTimestamp(2);
                lock.setExpiresAt(expiresAt.getTime());
                map.put(id, lock);
            }

            return map;
        }
    };
    return queryExecutor.query("select id, expires_at from sched_job_locks", rsh);
}
 
開發者ID:AirVantage,項目名稱:av-sched,代碼行數:26,代碼來源:JobLockDao.java

示例12: test_max_retry

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
@Test
public void test_max_retry() throws Exception {

    ResultSetHandler<String> rsh = mock(ResultSetHandler.class);
    String sql = "sql";

    SQLException ex1 = new SQLException("error 1");
    SQLException ex2 = new SQLException("error 2");
    SQLException ex3 = new SQLException("error 3");
    when(queryRunner.query(sql, rsh)).thenThrow(ex1, ex2, ex3);

    try {
        queryExecutor.query(sql, rsh);
        fail("SQLException should be raised");
    } catch (SQLException e) {
        assertEquals(ex3, e);
    }

    verify(queryRunner, times(3)).query(sql, rsh);
}
 
開發者ID:AirVantage,項目名稱:av-sched,代碼行數:21,代碼來源:QueryExecutorTest.java

示例13: mkResultSetHandler

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public static ResultSetHandler<List<Map<String, Object>>>
        mkResultSetHandler(String... names) {
    return (rs) -> {
        try {
            int columnCount = rs.getMetaData().getColumnCount();
            List<Map<String, Object>> result = new ArrayList<>();
            while (rs.next()) {
                Object[] data = readOneRow(rs, columnCount);
                result.add(arrayToMap(data, names));
            }
            return result;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    };
}
 
開發者ID:tminglei,項目名稱:binder-swagger-java,代碼行數:17,代碼來源:H2DB.java

示例14: getTypesOfRecords

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
public List< FieldType > getTypesOfRecords(Connection conn) throws Exception {
    List< FieldType > typesOfRecords = null;
    try {
        this.conn = conn;
        String sql = sqlCreator.getTypesOfRecordsSQL();
        if( sql != null ){
            DebugerLog.log("consulta: " + sql);
            QueryRunner qr = new QueryRunner();
            ResultSetHandler rsh = new BeanListHandler(FieldType.class);
            typesOfRecords = (List< FieldType>) qr.query(conn, sql, rsh);
        }
        if( typesOfRecords == null || typesOfRecords.isEmpty() ){
            typesOfRecords = new ArrayList< FieldType>();
            FieldType fieldType = new FieldType("");
            typesOfRecords.add(fieldType);
        }
        return typesOfRecords;
    } finally {
        ConnectionManager.closeConnection(conn);
    }
}
 
開發者ID:MxSIG,項目名稱:TableAliasV60,代碼行數:22,代碼來源:SqlExecutor.java

示例15: findFrenteManzana

import org.apache.commons.dbutils.ResultSetHandler; //導入依賴的package包/類
@Override
public FrenteManzana findFrenteManzana(String point, Server server)
		throws Exception {
	String sql = "select nomvial as vialidad, tipovial as tipoVialidad, nomref1 as entrevialidad1, nomref2 as entrevialidad2,"
			+ " tipovr1 as tipoEntrevialidad1, tipovr2 as tipoEntrevialidad2, nombre_loc as localidad, cve_loc as cveloc,"
			+ " nombre_mun as municipio, cve_mun as cvemun, nombre_ent as entidad, nomasen as asentamiento, cp as codigoPostal,"
			+ " ST_AsText(ST_Line_Interpolate_Point(ST_LineMerge(the_geom), ST_Line_Locate_Point(ST_LineMerge(the_geom), ST_GeomFromText(?, 900913)))) as punto,"
			+ " ST_Distance(ST_GeomFromText(?, 900913), the_geom) as distance"
			+ " from localidadesmzn.frentesdemanzana_mgn"
			+ " where ST_DWithin(ST_GeomFromText(?, 900913), the_geom, 40)"
			+ " order by distance" + " limit 1";
	Connection conn = ConnectionManager.getConnectionW(server);
	ResultSetHandler<FrenteManzana> rsh = new BeanHandler<FrenteManzana>(
			FrenteManzana.class);
	QueryRunner qr = new QueryRunner();
	FrenteManzana fm = null;
	try {
		fm = qr.query(conn, sql, rsh, point, point, point);
	} finally {
		ConnectionManager.closeConnection(conn);
	}
	return fm;
}
 
開發者ID:MxSIG,項目名稱:TableAliasV60,代碼行數:24,代碼來源:ImssDaoImpl.java


注:本文中的org.apache.commons.dbutils.ResultSetHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。