Java Code Examples for java.sql.ResultSet.getType()

The following are Jave code examples for showing how to use getType() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: uavstack   File: JdbcDriverAdapter.java   View Source Code Vote up 7 votes
/**
 * 解析resultset中的条数
 * 
 * @param resultSet
 * @return
 */
private String sqlResultSetParse(ResultSet rset) {

    try {
        // 只能向前遍历的游标,只能用next()来遍历
        if (rset.getType() == ResultSet.TYPE_FORWARD_ONLY) {
            return "FORWARD_ONLY";
        }
        else {
            // 可以滚动的游标,在用户使用游标之前,直接获取结果集大小,然后游标回到开始的地方(假装游标没有移动过)
            rset.last();
            int row = rset.getRow();
            rset.beforeFirst();
            return row + "";

        }
    }
    catch (SQLException e) {
        return e.toString();
    }
}
 
Example 2
Project: uroborosql   File: AuditLogSqlFilter.java   View Source Code Vote up 6 votes
@Override
public ResultSet doQuery(final SqlContext sqlContext, final PreparedStatement preparedStatement,
		final ResultSet resultSet) {
	// カウント初期値
	int rowCount = -1;
	try {
		// resultSetのカーソル種別を取得
		// 種別「TYPE_FORWARD_ONLY」の場合、beforeFirstメソッドが効かないため除外
		if (resultSet.getType() != ResultSet.TYPE_FORWARD_ONLY) {
			// 件数結果取得
			resultSet.last();
			rowCount = resultSet.getRow();
			resultSet.beforeFirst();
		}
	} catch (SQLException e) {
		// ここでの例外は実処理に影響を及ぼさないよう握りつぶす
	}

	String userName = getParam(sqlContext, USER_NAME_KEY);
	if (userName == null) {
		// ユーザ名が設定されていない時
		userName = DEFAULT_USER_NAME;
	}

	String funcId = getParam(sqlContext, FUNC_ID_KEY);
	if (funcId == null) {
		// 機能IDが設定されていない時
		funcId = DEFAULT_FUNC_ID;
	}

	LOG.debug(ToStringBuilder.reflectionToString(
			new AuditData(userName, funcId, sqlContext.getSqlId(), sqlContext.getSqlName(), sqlContext
					.getExecutableSql(), rowCount), ToStringStyle.JSON_STYLE));

	return resultSet;
}
 
Example 3
Project: uroborosql   File: DumpResultSqlFilter.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.filter.AbstractSqlFilter#doQuery(jp.co.future.uroborosql.context.SqlContext, java.sql.PreparedStatement, java.sql.ResultSet)
 */
@Override
public ResultSet doQuery(final SqlContext sqlContext, final PreparedStatement preparedStatement,
		final ResultSet resultSet) {
	try {
		if (resultSet.getType() == ResultSet.TYPE_FORWARD_ONLY) {
			LOG.warn("ResultSet type is TYPE_FORWARD_ONLY. DumpResultSqlFilter use ResultSet#beforeFirst(). Please Set TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE.");
		}
		StringBuilder builder = displayResult(resultSet);
		LOG.info(builder.toString());
	} catch (SQLException e) {
		e.printStackTrace();
	}
	return resultSet;
}