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


Java DriverManagerDataSource类代码示例

本文整理汇总了Java中org.springframework.jdbc.datasource.DriverManagerDataSource的典型用法代码示例。如果您正苦于以下问题:Java DriverManagerDataSource类的具体用法?Java DriverManagerDataSource怎么用?Java DriverManagerDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: entityManagerFactory

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

	JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();

	DriverManagerDataSource dataSource = new DriverManagerDataSource();
	dataSource.setUsername("root");
	dataSource.setPassword("");
	dataSource.setUrl("jdbc:mysql://localhost:3306/ensaiospring");
	dataSource.setDriverClassName("com.mysql.jdbc.Driver");

	Properties props = new Properties();
	props.setProperty("hibernate.dialect",
			"org.hibernate.dialect.MySQL5Dialect");
	props.setProperty("hibernate.show_sql", "true");
	props.setProperty("hibernate.hbm2ddl.auto", "update");

	factory.setJpaVendorAdapter(jpaVendorAdapter);
	factory.setDataSource(dataSource);
	factory.setJpaProperties(props);
	factory.setPackagesToScan("br.com.ciaware.springmvc.ensaio.models");

	return factory;
}
 
开发者ID:flaviociaware,项目名称:cwEnsaiosWeb,代码行数:26,代码来源:JPAConfiguration.java

示例2: mysqlDataSource

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public DataSource mysqlDataSource() {

    DriverManagerDataSource dataSource = new DriverManagerDataSource();

    dataSource.setDriverClassName(MYSQL_DRIVER_CLASS_NAME);
    dataSource.setUrl(MYSQL_URL);
    dataSource.setUsername(MYSQL_USER_NAME);
    dataSource.setPassword(MYSQL_USER_PASSWORD);

    return dataSource;
}
 
开发者ID:brainysoon,项目名称:superhouse,代码行数:13,代码来源:DataConfig.java

示例3: setup

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Setup
public void setup() throws PropertyVetoException {
  dataSource = new DriverManagerDataSource();
  dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  dataSource.setUrl(propertyOr("jdbcUrl", "jdbc:mysql://127.0.0.1:3306?useSSL=false"));
  dataSource.setUsername(propertyOr("username", "root"));
  dataSource.setPassword(propertyOr("password", "root"));

  JdbcTemplate delegate = new JdbcTemplate(dataSource);
  delegate.setDataSource(dataSource);

  proxy = new SenderProxy(new JdbcTemplateSender(delegate));
  proxy.onMessages(updated -> counter.addAndGet(updated.size()));

  reporter = reporter(proxy);
  batch = new BatchJdbcTemplate(delegate, reporter);
  batch.setDataSource(dataSource);

  unbatch = new JdbcTemplate(dataSource);
  unbatch.setDataSource(dataSource);
  unbatch.update(CREATE_DATABASE);
  unbatch.update(DROP_TABLE);
  unbatch.update(CREATE_TABLE);
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:25,代码来源:AbstractBatchJdbcTemplateBenchmark.java

示例4: getCurrentUser

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
public static LeafUser getCurrentUser() {
	LeafUser leafuser = null;
	User User = null;
	Authentication a = SecurityContextHolder.getContext().getAuthentication();
	try{
		if(a.getPrincipal() != null) {
			User = (User) a.getPrincipal();
		} else {
			return null;
		}
	}catch(Exception e) {
		return null;
	}
	if(User!=null) {
		DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); 
		JdbcUserDAO userDAO = new JdbcUserDAO();
		userDAO.setDataSource(datasource);
		leafuser = userDAO.loadUserByUsername(User.getUsername());
	}
	return leafuser;
}
 
开发者ID:DineshKumarBose,项目名称:LeafAccounts,代码行数:22,代码来源:UserUtil.java

示例5: getUserFromToken

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
public static LeafUser getUserFromToken(String token) {
	//return new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseUserFromToken(token);
	Claims claims =  new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseJWT(token);
	String claimsId = claims.getId();
	DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource();
       // Inject the datasource into the dao
   	JdbcUserDAO userDAO = new JdbcUserDAO();
   	userDAO.setDataSource(datasource);
	LeafUser user = userDAO.findByCustomerId(Integer.parseInt(claimsId));
	if(user.getUsername().equals(claims.getIssuer()) && user.getEmail().equals(claims.getSubject())) {
		return user;
	}
	else {
		return null;
	}
}
 
开发者ID:DineshKumarBose,项目名称:LeafAccounts,代码行数:17,代码来源:UserUtil.java

示例6: createDataSource

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * Creates and returns a new data source from the given connection information. Creates a new {@link DriverManagerDataSource}.
 *
 * @param jdbcConnection the JDBC connection
 * @param variables the optional map of key-value for expression evaluation
 *
 * @return a new {@link DataSource}
 */
private DataSource createDataSource(JdbcConnection jdbcConnection, Map<String, Object> variables)
{
    String url = evaluate(jdbcConnection.getUrl(), variables, "jdbc connection url");
    String username = evaluate(jdbcConnection.getUsername(), variables, "jdbc connection username");
    String password = evaluate(jdbcConnection.getPassword(), variables, "jdbc connection password");

    validateUrl(url);

    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
    driverManagerDataSource.setUrl(url);
    driverManagerDataSource.setUsername(username);
    driverManagerDataSource.setPassword(password);
    driverManagerDataSource.setDriverClassName(getDriverClassName(jdbcConnection.getDatabaseType()));
    return driverManagerDataSource;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:24,代码来源:JdbcServiceImpl.java

示例7: dataSource

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean(name = "dataSource")
public DataSource dataSource() {
    DriverManagerDataSource ds = new DriverManagerDataSource();
    ds.setDriverClassName(driverClassName);
    ds.setUrl(databaseUrl);

    Properties p = new Properties();
    Map<String, String> datasourceProperties = mapPropertyNames("datasource", hibernateConfiguration());
    p.putAll(datasourceProperties);
    ds.setConnectionProperties(p);
    if (!StringUtils.isEmpty(username)) {
        ds.setUsername(username);
    }
    if (!StringUtils.isEmpty(password)) {
        ds.setPassword(password);
    }
    return ds;
}
 
开发者ID:thunderbird,项目名称:pungwecms,代码行数:19,代码来源:JPAConfiguration.java

示例8: configureDataSource

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public DataSource configureDataSource() {
    log.info("*************** Env Variables configureDataSource *************** ");

    String driver = System.getenv(EnviromentVariables.DATASOURCE_DRIVER_CLASS.getCode());
    String url = System.getenv(EnviromentVariables.DATASOURCE_URL.getCode());
    String username = System.getenv(EnviromentVariables.DATASOURCE_USERNAME.getCode());
    String password = System.getenv(EnviromentVariables.DATASOURCE_PASSWORD.getCode());

    log.info("dataSource.driverClassName:    " + driver);
    log.info("dataSource.url:                " + url);
    log.info("dataSource.username:           " + username);
    log.info("dataSource.password:           ***");

    log.info("*************** END Env Variables configureDataSource *************** ");

    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);

    return dataSource;
}
 
开发者ID:macielbombonato,项目名称:apolo,代码行数:25,代码来源:PersistenceConfig.java

示例9: getDataSource

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * @param host
 * @param port
 * @param service
 * @param user
 * @param pw
 * @return
 * @throws Exception
 */
public DriverManagerDataSource getDataSource(String host, String port, String service, String user, String pw) throws Exception
{
	// Override this method if your datasource is different
	try
	{
		DriverManagerDataSource dataSource = new DriverManagerDataSource();

		dataSource.setDriverClassName(JDBC_DRIVER);
		String url = String.format("jdbc:oracle:thin:@%s:%s:%s", host, port, service);
		dataSource.setUrl(url);
		dataSource.setUsername(user);
		dataSource.setPassword(pw);

		return dataSource;
	}
	catch (Exception e)
	{
		throw new Exception("Unable to get data source. Reason: " + e.getMessage());
	}
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:30,代码来源:JdbcEngine.java

示例10: setup

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * Setup of test data: set attributes, purge and initialize test datbase 
 */
@Before
public void setup() throws SQLException, LiquibaseException {
	// Init jdbcTemplate
	this.jdbcTemplate = new JdbcTemplate(datasource);
	
	// Set test db properties
	DriverManagerDataSource ds = (DriverManagerDataSource)datasource;
	this.paasTestDbUrl = ds.getUrl();
	this.paasTestDbUser = ds.getUsername();
	this.paasTestDbPassword = ds.getPassword();

	// purge test database
	liquibaseWrapper.purgeDatabase(paasTestDbUrl, paasTestDbUser, paasTestDbPassword);
	
	// init database state
	liquibaseWrapper.applyChangeLog(paasTestDbUrl, paasTestDbUser, paasTestDbPassword, basicInitialChangeLofFile);
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:21,代码来源:CheckVariousRefactoringCommandsIT.java

示例11: createDriverManagerDataSources

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * 建立多個DriverManagerDataSource
 * 
 * @return
 * @throws Exception
 */
protected DriverManagerDataSource[] createDriverManagerDataSources() throws Exception {
	DriverManagerDataSource[] result = null;
	try {
		int maxDataSourceSize = extendedProperties.getInt(MAX_DATA_SOURCE_SIZE, DEFAULT_MAX_DATA_SOURCE_SIZE);
		result = new DriverManagerDataSource[maxDataSourceSize];
		//
		for (int i = 0; i < maxDataSourceSize; i++) {
			DriverManagerDataSource dataSource = createDriverManagerDataSource(i);
			result[i] = dataSource;
		}
	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during createDriverManagerDataSources()").toString(),
				e);
		try {
			result = (DriverManagerDataSource[]) shutdownDriverManagerDataSources();
		} catch (Exception sie) {
			throw sie;
		}
		throw e;
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:29,代码来源:DriverManagerDataSourceGroupFactoryBean.java

示例12: shutdownDriverManagerDataSources

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * 關閉
 *
 * @return
 */
protected DriverManagerDataSource[] shutdownDriverManagerDataSources() throws Exception {
	try {
		if (this.driverManagerDataSources != null) {
			for (int i = 0; i < this.driverManagerDataSources.length; i++) {
				DriverManagerDataSource oldInstance = this.driverManagerDataSources[i];
				// oldInstance.close();
				this.driverManagerDataSources[i] = null;
			}
			//
			this.driverManagerDataSources = null;
		}
	} catch (Exception e) {
		LOGGER.error(
				new StringBuilder("Exception encountered during shutdownDriverManagerDataSources()").toString(), e);
		throw e;
	}
	return this.driverManagerDataSources;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:24,代码来源:DriverManagerDataSourceGroupFactoryBean.java

示例13: setup

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Before
public void setup() {
	DriverManagerDataSource dataSource = new DriverManagerDataSource();
	dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
	dataSource.setUrl(DATASOURCE_URL);
	dataSource.setUsername(DATASOURCE_USER_NAME);
	dataSource.setPassword(DATASOURCE_USER_PASSWORD);
	this.dataSource = dataSource;
	try {
		this.server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
				.start();
	}
	catch (SQLException e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-task,代码行数:17,代码来源:JpaApplicationTests.java

示例14: getPool

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 * 获得一个可用的池
 * 
 * @param ds
 * @param profile
 * @param max 当Max==0时等同于Nopool
 * @return
 */
public static IUserManagedPool getPool(DataSource ds, int min,int max,TransactionMode txMode) {
	if(txMode==TransactionMode.JDBC || txMode==TransactionMode.JTA){
		max=0;
	}
	if(min==0){
		min = JefConfiguration.getInt(DbCfg.DB_CONNECTION_POOL, 3);
	}
	IUserManagedPool result;
	if (ds instanceof IRoutingDataSource) {
		IRoutingDataSource rds = (IRoutingDataSource) ds;
		result= new RoutingDummyConnectionPool(rds);
	} else if(ds instanceof DriverManagerDataSource||ds instanceof SimpleDataSource){
           result= new SingleManagedConnectionPool(ds, min, max);
       } else{ 
		result= new SingleDummyConnectionPool(ds);
	}
	return result.setTransactionMode(txMode);
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:27,代码来源:PoolService.java

示例15: setUp

import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
 */
@Before
public void setUp() {
    final DataSource ds = new DriverManagerDataSource(System.getProperty("jdbc.url", "jdbc:sap://localhost:30115"),
            System.getProperty("jdbc.user", "hibernate"), System.getProperty("jdbc.password", "hibernate"));

    final LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(ds);
    builder.setProperty(AvailableSettings.DIALECT,
            System.getProperty("hibernate.dialect", HANAColumnStoreDialect.class.getName()));
    builder.setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    builder.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");

    builder.addAnnotatedClass(Employee.class);

    this.sessionFactory = builder.buildSessionFactory();

    final HibernateTemplate ht = new HibernateTemplate();
    ht.setSessionFactory(this.sessionFactory);

    ht.afterPropertiesSet();

    this.template = ht;

    final HibernateTransactionManager txnMgr = new HibernateTransactionManager();
    txnMgr.setDataSource(ds);
    txnMgr.setSessionFactory(this.sessionFactory);
    txnMgr.afterPropertiesSet();

    this.transactionTemplate = new TransactionTemplate(txnMgr);
}
 
开发者ID:aclemons,项目名称:hibernate-hdb-demo,代码行数:32,代码来源:TestEmployee.java


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