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


Java DataSourceUtils.getConnection方法代码示例

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


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

示例1: writeExecuteFlag

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Override
public void writeExecuteFlag(String appId, String busCode, String trxId, String pAppId, String pBusCode, String pTrxId, int status) {
	
	Connection connection = DataSourceUtils.getConnection(selctor.selectDataSource(appId, busCode, trxId));
	
	try {
		PreparedStatement prepareStatement = connection.prepareStatement("INSERT INTO `executed_trans` (`app_id`, `bus_code`, `trx_id`,`p_app_id`, `p_bus_code`, `p_trx_id`,`status`) VALUES ( ?, ?, ?, ?, ?, ?, ?);");
		prepareStatement.setString(1, appId);
		prepareStatement.setString(2, busCode);
		prepareStatement.setString(3, trxId);
		prepareStatement.setString(4, pAppId);
		prepareStatement.setString(5, pBusCode);
		prepareStatement.setString(6, pTrxId);
		prepareStatement.setInt(7, status);
		
		int executeUpdate = prepareStatement.executeUpdate();
		if(executeUpdate != 1){
			throw new RuntimeException(String.format("insert count(%s) Error!%s %s %s %s %s %s %s", executeUpdate,appId,busCode,trxId,pAppId,pBusCode,pTrxId,status));
		}
	} catch (SQLException e) {
		throw new RuntimeException("insert Sql failed,check whether the same transaction has been executed?",e);
	}
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:24,代码来源:DefaultTransStatusLoggerImpl.java

示例2: findDefaultColumnType

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的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

示例3: loadTablePrimaryKeys

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的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

示例4: getNextKey

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的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

示例5: getConnection

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Override
public Connection getConnection() throws SQLException {
    TransactionProxy proxy = getProxy();
    if (proxy != null) {
        return proxy.getConnection();
    }
    //根据当前激活的数据源 获取jdbc链接
    DataSource dataSource = DataSourceHolder.currentDataSource().getNative();
    String dsId = switcher().currentDataSourceId();
    Connection connection = DataSourceUtils.getConnection(dataSource);
    proxy = new TransactionProxy(dsId, connection, dataSource);
    addProxy(proxy);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
                "DataSource (" + (dsId == null ? "default" : dsId) + ") JDBC Connection ["
                        + connection
                        + "] will"
                        + (proxy.isConnectionTransactional ? " " : " not ")
                        + "be managed by Spring");
    }

    return connection;
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:25,代码来源:DynamicSpringManagedTransaction.java

示例6: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
 * Execute the given {@link DatabasePopulator} against the given {@link DataSource}.
 * @param populator the {@code DatabasePopulator} to execute
 * @param dataSource the {@code DataSource} to execute against
 * @throws DataAccessException if an error occurs, specifically a {@link ScriptException}
 */
public static void execute(DatabasePopulator populator, DataSource dataSource) throws DataAccessException {
	Assert.notNull(populator, "DatabasePopulator must be provided");
	Assert.notNull(dataSource, "DataSource must be provided");
	try {
		Connection connection = DataSourceUtils.getConnection(dataSource);
		try {
			populator.populate(connection);
		}
		finally {
			if (connection != null) {
				DataSourceUtils.releaseConnection(connection, dataSource);
			}
		}
	}
	catch (Exception ex) {
		if (ex instanceof ScriptException) {
			throw (ScriptException) ex;
		}

		throw new UncategorizedScriptException("Failed to execute database script", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:DatabasePopulatorUtils.java

示例7: executeSql

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
protected void executeSql(String path) {
    logger.info("executeSql : " + path);

    Resource resource = new ClassPathResource(path, getClass());
    ResourceDatabasePopulator rdp = new ResourceDatabasePopulator();
    rdp.addScript(resource);
    rdp.setSqlScriptEncoding("UTF-8");
    rdp.setIgnoreFailedDrops(true);
    rdp.setContinueOnError(false);

    try (Connection conn = DataSourceUtils.getConnection(dataSource)) {
        rdp.populate(conn);
    }
    catch (Exception e) {
        throw new IllegalStateException("executeSql failed, path=" + path, e);
    }
}
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:18,代码来源:SpringTestBase.java

示例8: checkConnection

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
 */
private void checkConnection() {
    Connection conn = DataSourceUtils.getConnection(jdbc.getDataSource());

    assertNotNull(conn);

    try {
        assertFalse(conn.isClosed());
        assertEquals(!ses.isWithinTransaction(), conn.getAutoCommit());
    }
    catch (SQLException e) {
        throw new RuntimeException(e);
    }

    verifySameInstance(conn);
}
 
开发者ID:apache,项目名称:ignite,代码行数:18,代码来源:CacheSpringStoreSessionListenerSelfTest.java

示例9: queryFactory

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Bean
public PostgresQueryFactory queryFactory() {
    final DataSource dataSource = dataSource();
    return new PostgresQueryFactory(querydslConfiguration(), new Provider<Connection>() {

        @Override
        public Connection get() {
          Connection conn = DataSourceUtils.getConnection(dataSource);
          if (!DataSourceUtils.isConnectionTransactional(conn, dataSource)) {
              throw new RuntimeException("Connection is not transactional");
          }
          return conn;
        }
        
    });
}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:17,代码来源:JdbcConfiguration.java

示例10: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
 * Execute the given DatabasePopulator against the given DataSource.
 * @param populator the DatabasePopulator to execute
 * @param dataSource the DataSource to execute against
 */
public static void execute(DatabasePopulator populator, DataSource dataSource) {
	Assert.notNull(populator, "DatabasePopulator must be provided");
	Assert.notNull(dataSource, "DataSource must be provided");
	try {
		Connection connection = DataSourceUtils.getConnection(dataSource);
		try {
			populator.populate(connection);
		}
		finally {
			if (connection != null) {
				DataSourceUtils.releaseConnection(connection, dataSource);
			}
		}
	}
	catch (Exception ex) {
		throw new DataAccessResourceFailureException("Failed to execute database script", ex);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:DatabasePopulatorUtils.java

示例11: getColumns

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
public List<Column> getColumns(String tableName) throws SQLException {
    List<Column> columns = new ArrayList<Column>();
    Connection connection = DataSourceUtils.getConnection(dataSource);
    DatabaseMetaData metaData = connection.getMetaData();
    ResultSet columnsResultSet = metaData.getColumns(null, metaData.getUserName(), tableName, "%");
    while (columnsResultSet.next()) {
        Column column = new Column();
        column.setColumnName(columnsResultSet.getString("COLUMN_NAME").toLowerCase());
        column.setDataType(columnsResultSet.getInt("DATA_TYPE"));
        column.setTypeName(columnsResultSet.getString("TYPE_NAME"));
        column.setColumnSize(columnsResultSet.getInt("COLUMN_SIZE"));
        column.setNullable(columnsResultSet.getInt("NULLABLE"));
        column.setRemarks(columnsResultSet.getString("REMARKS"));
        column.setColumnDef(columnsResultSet.getString("COLUMN_DEF"));
        column.setOrdinalPosition(columnsResultSet.getInt("ORDINAL_POSITION"));
        column.setIsNullable(columnsResultSet.getString("IS_NULLABLE"));
        column.setIsAutoincrement(columnsResultSet.getString("IS_AUTOINCREMENT"));
        columns.add(column);
    }
    DataSourceUtils.releaseConnection(connection, dataSource);
    return columns;
}
 
开发者ID:mynah,项目名称:oblatum,代码行数:23,代码来源:SqlGenerator.java

示例12: delete

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Override
public String delete(final String accountid) throws ProvisioningException {
    LOG.debug("Delete request received");

    Connection conn = null;
    try {
        conn = DataSourceUtils.getConnection(dataSource);

        try (PreparedStatement statement = conn.prepareStatement("DELETE FROM user WHERE userId=?")) {
            statement.setString(1, accountid);

            String query = "DELETE FROM user WHERE userId='" + accountid + "';";
            LOG.debug("Execute query: " + query);

            statement.executeUpdate();
        }

        return accountid;
    } catch (SQLException e) {
        throw new ProvisioningException("Delete operation failed", e);
    } finally {
        DataSourceUtils.releaseConnection(conn, dataSource);
    }
}
 
开发者ID:apache,项目名称:syncope,代码行数:25,代码来源:ProvisioningImpl.java

示例13: populateDatabase

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Bean
@Lazy(false)
public ResourceDatabasePopulator populateDatabase() throws SQLException {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("data.sql"));

    Connection connection = null;

    try {
        connection = DataSourceUtils.getConnection(dataSource());
        populator.populate(connection);
    } finally {
        if (connection != null) {
            DataSourceUtils.releaseConnection(connection, dataSource());
        }
    }

    return populator;
}
 
开发者ID:mhmxs,项目名称:SpringClips,代码行数:20,代码来源:PersistenceConfigurarion.java

示例14: getQueryRunner

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
 * 添加支持jdbc datasource Transaction 支持的QueryRunner处理方式
 */
@Override
protected QueryRunner getQueryRunner() {
	
	return new QueryRunner(dataSource){

		/* (non-Javadoc)
		 * @see org.apache.commons.dbutils.AbstractQueryRunner#prepareConnection()
		 */
		@Override
		protected Connection prepareConnection() throws SQLException {
			return DataSourceUtils.getConnection(this.getDataSource());
		}

		/* (non-Javadoc)
		 * @see org.apache.commons.dbutils.AbstractQueryRunner#close(java.sql.Connection)
		 */
		@Override
		protected void close(Connection conn) throws SQLException {
			DataSourceUtils.releaseConnection(conn, getDataSource());
		}
		
	};
}
 
开发者ID:bluesky8318,项目名称:CommonDao,代码行数:27,代码来源:JdbcTxCommonDao.java

示例15: getRateTableColumnNames

import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
 * Returns a list of column names read from the rate table in the database.
 * @return column names
 */
public List<String> getRateTableColumnNames() {
    DataSource dataSource = jdbcTemplate.getDataSource();
    Connection connection = DataSourceUtils.getConnection(dataSource);

    List<String> columns = Collections.emptyList();

    try {
        columns = JDBCUtils.getAllColumnNames(connection, rateCard.getTableName());
    } catch (SQLException e) {
        throw new SessionInternalError("Could not read columns from rate card table.", e,
                                       new String[] { "RateCardWS,rates,rate.card.cannot.read.rating.table" });

    } finally {
        DataSourceUtils.releaseConnection(connection, dataSource);
    }

    return columns;
}
 
开发者ID:maxdelo77,项目名称:replyit-master-3.2-final,代码行数:23,代码来源:RateCardBL.java


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