當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。