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


Java JdbcUtils.closeConnection方法代码示例

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


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

示例1: 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

示例2: 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

示例3: initDefaultDbInfo

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
/**
 * 初始化默认数据库配置信息
 * 
 * @return 返回DbInfo对象
 * @throws Exception
 */
public DbInfo initDefaultDbInfo() throws Exception {
	DbInfo dbInfo = new DbInfo();
	dbInfo.setId(DbConstants.DEFAULTDATASOURCE);
	Connection conn = null;
	try {
		conn = this.getJdbcTemplate().getDataSource().getConnection();
		DatabaseMetaData metaData = conn.getMetaData();
		dbInfo.setDbType(metaData.getDatabaseProductName());
		dbInfo.setName("默认连接" + dbInfo.getDbType());
		dbInfo.setUrl(metaData.getURL());
		dbInfo.setUsername(metaData.getUserName());
		dbInfo.setProductName(metaData.getDatabaseProductName());
		dbInfo.setProductVersion(metaData.getDatabaseProductVersion());
	} finally {
		JdbcUtils.closeConnection(conn);
	}
	return dbInfo;

}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:26,代码来源:DbService.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: 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

示例6: releaseConnection

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public void releaseConnection(Connection con) {
	if (sessionConnectionMethod != null) {
		// Need to explicitly call close() with Hibernate 3.x in order to allow
		// for eager release of the underlying physical Connection if necessary.
		// However, do not do this on Hibernate 4.2+ since it would return the
		// physical Connection to the pool right away, making it unusable for
		// further operations within the current transaction!
		JdbcUtils.closeConnection(con);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:HibernateJpaDialect.java

示例7: buildDatabaseTables

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public void buildDatabaseTables(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	Connection conn=null;
	ResultSet rs = null;
	try{
		conn=buildConnection(req);
		DatabaseMetaData metaData = conn.getMetaData();
		String url = metaData.getURL();
		String schema = null;
		if (url.toLowerCase().contains("oracle")) {
			schema = metaData.getUserName();
		}
		List<Map<String,String>> tables = new ArrayList<Map<String,String>>();
		rs = metaData.getTables(null, schema, "%", new String[] { "TABLE","VIEW" });
		while (rs.next()) {
			Map<String,String> table = new HashMap<String,String>();
			table.put("name",rs.getString("TABLE_NAME"));
			table.put("type",rs.getString("TABLE_TYPE"));
			tables.add(table);
		}
		writeObjectToJson(resp, tables);
	}catch(Exception ex){
		throw new ServletException(ex);
	}finally{
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeConnection(conn);
	}
}
 
开发者ID:youseries,项目名称:ureport,代码行数:28,代码来源:DatasourceServletAction.java

示例8: findTableInfos

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public List<TableInfo> findTableInfos(String dbInfoId) throws Exception {
	List<TableInfo> tablesList = new ArrayList<TableInfo>();
	DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
	Connection conn = null;
	ResultSet rs = null;
	try {
		conn = DataSourceUtils.getConnection(ds);
		DatabaseMetaData metaData = conn.getMetaData();
		String url = metaData.getURL();
		String schema = null;
		if (url.toLowerCase().contains("oracle")) {
			String value = Configure.getString("bdf2.default.schema");
			if (StringUtils.hasText(value)) {
				schema = value;
			} else {
				schema = metaData.getUserName();
			}
		}
		rs = metaData.getTables(null, schema, "%", new String[] { "TABLE" });
		TableInfo tableInfo = null;
		while (rs.next()) {
			tableInfo = new TableInfo();
			tableInfo.setTableName(rs.getString("TABLE_NAME"));
			tableInfo.setDbInfoId(dbInfoId);
			tablesList.add(tableInfo);
		}
		return tablesList;
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeConnection(conn);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:33,代码来源:DbCommonServiceImpl.java

示例9: 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

示例10: close

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public void close(boolean closeConnection) {
	JdbcUtils.closeResultSet(rs);
	rs = null;
	JdbcUtils.closeStatement(ps);
	ps = null;
	if (closeConnection) {
		JdbcUtils.closeConnection(con);
	}
	con = null;
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:11,代码来源:JdbcTable.java

示例11: doUnlock

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
protected void doUnlock() {
	Integer locked = this.locked.get();
	if (locked == null || locked != 1) {
		return;
	}
	//
	Integer unlocked = null;
	Connection conn = null;
	ResultSet rs = null;
	PreparedStatement ps = null;
	try {
		conn = this.connection.get();
		ps = conn.prepareStatement(this.unlockSql);
		// lock id
		ps.setString(1, this.id);
		//
		rs = ps.executeQuery();
		if (rs.next()) {
			unlocked = rs.getInt(1);
			if (rs.wasNull()) {
				unlocked = null;
			}
		}
		//
		if (unlocked == null || unlocked == 0) {
			// 無法釋放鎖, 有可能是重複釋放, 只寫log, 不拋出ex
			LOGGER.warn("Could not release lock: " + id);
		}
	} catch (Throwable e) {
		throw new DistributedLockException("Could not release lock: " + id, e);
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(ps);
		this.connection.set(null);
		// conn return to pool
		JdbcUtils.closeConnection(conn);
		this.locked.set(null);
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:41,代码来源:MysqlLockImpl.java

示例12: listMonitor

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public List<Monitor> listMonitor()
{
    List<Monitor> monitors = new ArrayList<Monitor>();
    
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement stmt = null;
    
    try
    {
    	con = dataSource.getConnection();
        con.setReadOnly(true);
        stmt = con.prepareStatement("select * from t_monitor");
        rs = stmt.executeQuery();
                
        while(rs.next()) {
            
            monitors.add(createMonitor(rs));
        }
    }
    catch (SQLException e)
    {
        e.printStackTrace();
    }
    finally
    {
        JdbcUtils.closeResultSet(rs);
        JdbcUtils.closeStatement(stmt);
        JdbcUtils.closeConnection(con);
    }
    
    return monitors;
}
 
开发者ID:zdtjss,项目名称:nway-jdbc,代码行数:35,代码来源:JdbcPerformance.java

示例13: queryMonitorJsonList

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public String queryMonitorJsonList()
{
    StringBuilder json = new StringBuilder(1000);
    
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement stmt = null;
    
    try
    {
    	con = dataSource.getConnection();
        con.setReadOnly(true);
        stmt = con.prepareStatement("select * from t_monitor");
        rs = stmt.executeQuery();
                
        while(rs.next()) {
            
            json.append(buildJson(rs));
        }
    }
    catch (SQLException e)
    {
        e.printStackTrace();
    }
    finally
    {
        JdbcUtils.closeResultSet(rs);
        JdbcUtils.closeStatement(stmt);
        JdbcUtils.closeConnection(con);
    }
    
    return json.toString();
}
 
开发者ID:zdtjss,项目名称:nway-jdbc,代码行数:35,代码来源:JdbcPerformance.java

示例14: releaseConnection

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
public void releaseConnection(Connection con) {
	if (sessionConnectionMethod != null) {
		// Need to explicitly call close() with Hibernate 3.x in order to allow
		// for eager release of the underlying physical Connection if necessary.
		// However, do not do this on Hibernate 4.2+ since it would return the
		// physical Connection to the pool right away, making it unusable for
		// further operations within the current transaction!
		JdbcUtils.closeConnection(con);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:HibernateJpaDialect.java

示例15: releaseConnection

import org.springframework.jdbc.support.JdbcUtils; //导入方法依赖的package包/类
@Override
public void releaseConnection(Connection con) {
	JdbcUtils.closeConnection(con);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:OpenJpaDialect.java


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