当前位置: 首页>>代码示例>>Java>>正文


Java JdbcUtils.closeResultSet方法代码示例

本文整理汇总了Java中org.springframework.jdbc.support.JdbcUtils.closeResultSet方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcUtils.closeResultSet方法的具体用法?Java JdbcUtils.closeResultSet怎么用?Java JdbcUtils.closeResultSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.jdbc.support.JdbcUtils的用法示例。


在下文中一共展示了JdbcUtils.closeResultSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTablePrimaryKeys

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
private String loadTablePrimaryKeys(String tableName,DatabaseMetaData metaData) throws Exception{
	String keys="";
	ResultSet rs = null;
	try {
		rs = metaData.getPrimaryKeys(null, null, tableName.toUpperCase());
		int i=0;
		while (rs.next()) {
			if(i>0){
				keys+=",";
			}
			i++;
			keys+=rs.getString("COLUMN_NAME");
		}
	} finally {
		JdbcUtils.closeResultSet(rs);
	}
	return keys;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:19,代码来源:QueryWizardPR.java

示例2: getNextKey

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Executes the SQL as specified by {@link #getSequenceQuery()}.
 */
@Override
protected long getNextKey() throws DataAccessException {
	Connection con = DataSourceUtils.getConnection(getDataSource());
	Statement stmt = null;
	ResultSet rs = null;
	try {
		stmt = con.createStatement();
		DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
		rs = stmt.executeQuery(getSequenceQuery());
		if (rs.next()) {
			return rs.getLong(1);
		}
		else {
			throw new DataAccessResourceFailureException("Sequence query did not return a result");
		}
	}
	catch (SQLException ex) {
		throw new DataAccessResourceFailureException("Could not obtain sequence value", ex);
	}
	finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(stmt);
		DataSourceUtils.releaseConnection(con, getDataSource());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AbstractSequenceMaxValueIncrementer.java

示例3: readPrimaryKeyNames

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
private static Collection<String> readPrimaryKeyNames(DatabaseMetaDataWrapper metaData, String tableName)
                                                                                                         throws SQLException {
    ResultSet pkData = null;

    try {
        List<String> pks = new ArrayList<String>();
        Map<String, Object> values;

        for (pkData = metaData.getPrimaryKeys(tableName); pkData.next(); pks.add(readPrimaryKeyName(metaData,
            values))) {
            values = readColumns(pkData, initColumnsForPK());
        }

        return pks;
    } finally {
        JdbcUtils.closeResultSet(pkData);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:19,代码来源:DdlUtils.java

示例4: loadTablePrimaryKeys

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
private List<String> loadTablePrimaryKeys(String tableName)throws Exception{
	DataSource ds=this.getJdbcTemplate().getDataSource();
	Connection con = DataSourceUtils.getConnection(ds);
	List<String> primaryKeyList=new ArrayList<String>();
	Statement stmt = null;
	ResultSet rs=null;
	try{
		DatabaseMetaData metaData = con.getMetaData();
		rs = metaData.getPrimaryKeys(null, null, tableName.toUpperCase());
		while (rs.next()) {
			primaryKeyList.add(rs.getString("COLUMN_NAME"));
		}
	}finally{
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(stmt);
		JdbcUtils.closeConnection(con);
	}
	return primaryKeyList;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:20,代码来源:EntityPR.java

示例5: findDefaultColumnType

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public List<String> findDefaultColumnType(String dbInfoId) throws Exception {
	DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
	Connection conn = null;
	ResultSet resultSet = null;
	try {
		conn = DataSourceUtils.getConnection(ds);
		DatabaseMetaData metaData = conn.getMetaData();
		resultSet = metaData.getTypeInfo();
		List<String> list = new ArrayList<String>();
		while (resultSet.next()) {
			String typeName = resultSet.getString("TYPE_NAME").toUpperCase();
			list.add(typeName);
		}
		return list;
	} finally {
		JdbcUtils.closeResultSet(resultSet);
		JdbcUtils.closeConnection(conn);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:20,代码来源:DbCommonServiceImpl.java

示例6: findTablePrimaryKeys

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public List<String> findTablePrimaryKeys(String dbInfoId, String tableName) throws Exception {
	List<String> primaryKeys = new ArrayList<String>();
	Connection con = null;
	ResultSet rs = null;
	DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
	try {
		con = ds.getConnection();
		DatabaseMetaData metaData = con.getMetaData();
		rs = metaData.getPrimaryKeys(null, null, tableName.toUpperCase());
		while (rs.next()) {
			primaryKeys.add(rs.getString("COLUMN_NAME").toUpperCase());
		}
		return primaryKeys;
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeConnection(con);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:19,代码来源:DbCommonServiceImpl.java

示例7: allTablesExist

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * check if all tables from given array/collection exist in database.
 * 
 * @param connection
 *            actual jdbc connection
 * @param tables
 *            array of tables
 * @return true if all tables from given collection exist.
 * @throws java.sql.SQLException
 *             if JDBC exception occurred
 */
public static boolean allTablesExist(Connection connection, String[] tables) throws SQLException {
	boolean tablesCreated = true;
	for (String table : tables) {
		ResultSet resultSet = null;
		try {
			resultSet = connection.getMetaData().getTables(connection.getCatalog(), null, table, null);
			if (!resultSet.next()) {
				tablesCreated = false;
				logger.debug("table " + table + " does not exist");
			} else {
				logger.debug("table " + table + "  already exists");
			}
		} finally {
			JdbcUtils.closeResultSet(resultSet);
		}
	}
	logger.debug("tablesCreated(connection=>" + connection + ",tables=>" + tables + "):=" + tablesCreated + "]");
	return tablesCreated;
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:31,代码来源:DataAccessUtility.java

示例8: exists

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Checks whether the database contains a table matching these criteria.
 * 
 * @param catalog
 *            The catalog where the table resides. (optional)
 * @param schema
 *            The schema where the table resides. (optional)
 * @param table
 *            The name of the table. (optional)
 * @param tableTypes
 *            The types of table to look for (ex.: TABLE). (optional)
 * @return {@code true} if a matching table has been found, {@code false} if
 *         not.
 * @throws SQLException
 *             when the check failed.
 */
protected boolean exists(Schema catalog, Schema schema, String table, String... tableTypes) throws SQLException {
    Connection connection = jdbcTemplate.getDataSource().getConnection();
    String[] types = tableTypes;
    if (types.length == 0) {
        types = null;
    }

    ResultSet resultSet = null;
    boolean found;
    try {
        resultSet = connection.getMetaData().getTables(catalog == null ? null : catalog.getName(), schema == null ? null : schema.getName(), table, types);
        found = resultSet.next();
    } finally {
        JdbcUtils.closeResultSet(resultSet);
        JdbcUtils.closeConnection(connection);
    }

    return found;
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:36,代码来源:JdbcTable.java

示例9: hasPrimaryKey

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Checks whether the table has a primary key.
 * 
 * @return {@code true} if a primary key has been found, {@code false} if
 *         not.
 */
public boolean hasPrimaryKey() {
    ResultSet resultSet = null;
    boolean found;
    try {
        if (dbSupport.catalogIsSchema()) {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getPrimaryKeys(schema.getName(), null, name);
        } else {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getPrimaryKeys(null, schema.getName(), name);
        }
        found = resultSet.next();
    } catch (SQLException e) {
        throw new DatabaseException("Unable to check whether table " + this + " has a primary key", e);
    } finally {
        JdbcUtils.closeResultSet(resultSet);
    }

    return found;
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:25,代码来源:JdbcTable.java

示例10: hasColumn

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Checks whether the database contains a column matching these criteria.
 * 
 * @param column
 *            The column to look for.
 * @return {@code true} if a matching column has been found, {@code false}
 *         if not.
 */
public boolean hasColumn(String column) {
    ResultSet resultSet = null;
    boolean found;
    try {
        if (dbSupport.catalogIsSchema()) {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getColumns(schema.getName(), null, name, column);
        } else {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getColumns(null, schema.getName(), name, column);
        }
        found = resultSet.next();
    } catch (SQLException e) {
        throw new DatabaseException("Unable to check whether table " + this + " has a column named " + column, e);
    } finally {
        JdbcUtils.closeResultSet(resultSet);
    }

    return found;
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:27,代码来源:JdbcTable.java

示例11: getColumnSize

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Determines the size (in characters) of this column.
 * 
 * @param column
 *            The column to look for.
 * @return The size (in characters).
 */
public int getColumnSize(String column) {
    ResultSet resultSet = null;
    int columnSize;
    try {
        if (dbSupport.catalogIsSchema()) {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getColumns(schema.getName(), null, name, column);
        } else {
            resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getColumns(null, schema.getName(), name, column);
        }
        resultSet.next();
        columnSize = resultSet.getInt("COLUMN_SIZE");
    } catch (SQLException e) {
        throw new DatabaseException("Unable to check the size of column " + column + " in table " + this, e);
    } finally {
        JdbcUtils.closeResultSet(resultSet);
    }

    return columnSize;
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:27,代码来源:JdbcTable.java

示例12: allTypes

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * Retrieves all the types in this schema.
 * 
 * @return All types in the schema.
 */
public final Type[] allTypes() {
    ResultSet resultSet = null;
    try {
        resultSet = jdbcTemplate.getDataSource().getConnection().getMetaData().getUDTs(null, name, null, null);

        List<Type> types = new ArrayList<Type>();
        while (resultSet.next()) {
            types.add(getType(resultSet.getString("TYPE_NAME")));
        }

        return types.toArray(new Type[types.size()]);
    } catch (SQLException e) {
        throw new DatabaseException("Unable to retrieve all types in schema " + this, e);
    } finally {
        JdbcUtils.closeResultSet(resultSet);
    }
}
 
开发者ID:PkayJava,项目名称:pluggable,代码行数:23,代码来源:Schema.java

示例13: handle

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public Long handle(ResultSet rs) {
    try {
        while (rs.next()) {
            return rs.getLong(1);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        JdbcUtils.closeResultSet(rs);
    }
    return 0L;
}
 
开发者ID:lftao,项目名称:jkami,代码行数:14,代码来源:NumberHandle.java

示例14: query

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public <T> T query(final String sql, final ResultSetExtractor<T> rse) throws DataAccessException {
	Assert.notNull(sql, "SQL must not be null");
	Assert.notNull(rse, "ResultSetExtractor must not be null");
	if (logger.isDebugEnabled()) {
		logger.debug("Executing SQL query [" + sql + "]");
	}
	class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
		@Override
		public T doInStatement(Statement stmt) throws SQLException {
			ResultSet rs = null;
			try {
				rs = stmt.executeQuery(sql);
				ResultSet rsToUse = rs;
				if (nativeJdbcExtractor != null) {
					rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
				}
				return rse.extractData(rsToUse);
			}
			finally {
				JdbcUtils.closeResultSet(rs);
			}
		}
		@Override
		public String getSql() {
			return sql;
		}
	}
	return execute(new QueryStatementCallback());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:JdbcTemplate.java

示例15: loadDbTables

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@DataProvider
public Collection<TableDef> loadDbTables() throws Exception{
	Collection<TableDef> result=new ArrayList<TableDef>();
	DataSource ds=this.getJdbcTemplate().getDataSource();
	Connection con = DataSourceUtils.getConnection(ds);
	Statement stmt = null;
	ResultSet rs=null;
	try{
		DatabaseMetaData metaData = con.getMetaData();
		String url=metaData.getURL();
		String schema=null;
		if(url.toLowerCase().contains("oracle")){
			schema=metaData.getUserName();
		}
		rs = metaData.getTables(null,schema, "%",new String[] { "TABLE" });
		while (rs.next()) {
			TableDef table=new TableDef();
			table.setName(rs.getString("TABLE_NAME"));
			table.setPrimaryKeys(loadTablePrimaryKeys(table.getName(),metaData));
			result.add(table);
		}
	}finally{
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(stmt);
		JdbcUtils.closeConnection(con);
	}
	return result;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:29,代码来源:QueryWizardPR.java


注:本文中的org.springframework.jdbc.support.JdbcUtils.closeResultSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。