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


Java BasicDataSource类代码示例

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


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

示例1: getInfo

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
  DataSourceInfo dataSourceInfo = null;
  if (canMap(resource)) {
    BasicDataSource source = (BasicDataSource) resource;
    dataSourceInfo = new DataSourceInfo();
    dataSourceInfo.setBusyConnections(source.getNumActive());
    dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
    dataSourceInfo.setMaxConnections(source.getMaxTotal());
    dataSourceInfo.setJdbcUrl(source.getUrl());
    dataSourceInfo.setUsername(source.getUsername());
    dataSourceInfo.setResettable(false);
    dataSourceInfo.setType("tomcat-dbcp2");
  }
  return dataSourceInfo;
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:17,代码来源:Tomcat8DbcpDatasourceAccessor.java

示例2: ConnectionDB

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
private ConnectionDB ()
{
	pool = new BasicDataSource();
	pool.setDriverClassName("com.mysql.jdbc.Driver");
	pool.setUsername("root");
	pool.setPassword("1111");
	pool.setUrl("jdbc:mysql://localhost/videogameshop");
	pool.setInitialSize(40); 

}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:11,代码来源:ConnectionDB.java

示例3: findById

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
@Override
public LineaCompra findById(String id) {
	
	LineaCompra l = null;
	
	try
	{
		BasicDataSource basicDataSource = ConnectionDB.getInstancia().getPool();
		Connection conexion = basicDataSource.getConnection();
		
		
		String query = "select * from lineacompra where login = ?" ;
		
		PreparedStatement s = conexion.prepareStatement(query);
    
		s.setString(1,id);
    
		ResultSet rs = s.executeQuery ();
    
		if (rs.next())
		{
			l = new LineaCompra();
			l.setId(rs.getString(1));
			l.setIdcompra(rs.getString(2));
			l.setCantidad(rs.getInt(3));
			l.setSubtotal(rs.getFloat(4));

		}
        conexion.close();
		
	}catch (Exception ex)
	{
		System.out.println ("Error"+ex.getMessage());
	}


	return l;
}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:39,代码来源:DAOLineaCompra.java

示例4: findById

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
@Override
public Usuario findById(String key) {
	Connection conexion = null;
	Usuario u = null;
	try
	{
		ConnectionDB pool = ConnectionDB.getInstancia();
		BasicDataSource datasource = pool.getPool();
		conexion = datasource.getConnection();
		
			
		String query = "select * from usuario where nick = ?" ;
		
		PreparedStatement s = conexion.prepareStatement(query);
    
		s.setString(1,key);
    
		ResultSet result = s.executeQuery ();
    
		if (result.next())
		{
			u = new Usuario();
			u.setId(result.getInt(1));
			u.setNombre(result.getString(2));
			u.setApellidos(result.getString(3));
			u.setDni(result.getString(4));
			u.setEmail(result.getString(5));
			u.setNick(result.getString(6));
			u.setPsswd(result.getString(7));
			u.setIsadmin(result.getBoolean(8));
		}
        conexion.close();
	}
	catch (Exception ex)
   	{
   		System.out.println ("Error"+ex.getMessage());
   	}

	return u;
}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:41,代码来源:DAOUsuario.java

示例5: Tomcat8DbcpDatasourceAccessor

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Tomcat 8 dbcp datasource accessor.
 *
 * @throws Exception the exception
 */
@Test
public void Tomcat8DbcpDatasourceAccessor() throws Exception {
  Tomcat8DbcpDatasourceAccessor accessor = new Tomcat8DbcpDatasourceAccessor();
  try (BasicDataSource source = new BasicDataSource()) {
    assertEquals("tomcat-dbcp2", accessor.getInfo(source).getType());
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:13,代码来源:Tomcat8DbcpDatasourceAccessorTest.java

示例6: Tomcat9DbcpDatasourceAccessor

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Tomcat 9 dbcp datasource accessor.
 *
 * @throws Exception the exception
 */
@Test
public void Tomcat9DbcpDatasourceAccessor() throws Exception {
  Tomcat9DbcpDatasourceAccessor accessor = new Tomcat9DbcpDatasourceAccessor();
  try (BasicDataSource source = new BasicDataSource()) {
    assertEquals("tomcat-dbcp2", accessor.getInfo(source).getType());
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:13,代码来源:Tomcat9DbcpDatasourceAccessorTest.java

示例7: Tomcat85DbcpDatasourceAccessor

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Tomcat 85 dbcp datasource accessor.
 *
 * @throws Exception the exception
 */
@Test
public void Tomcat85DbcpDatasourceAccessor() throws Exception {
  Tomcat85DbcpDatasourceAccessor accessor = new Tomcat85DbcpDatasourceAccessor();
  try (BasicDataSource source = new BasicDataSource()) {
    assertEquals("tomcat-dbcp2", accessor.getInfo(source).getType());
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:13,代码来源:Tomcat85DbcpDatasourceAccessorTest.java

示例8: newManagedDataSource

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Create a new {@link DataSource} whose lifecycle is managed by baseline.
 *
 * @param environment {@code Environment} instance for this baseline service
 * @param database database configuration block for configuring the {@code DataSource}
 * @return valid, new {@code DataSource} instance
 */
public static ManagedDataSource newManagedDataSource(Environment environment, DatabaseConfiguration database) {
    BasicDataSource dataSource = (BasicDataSource) newDataSource(database);
    registerGauges(dataSource);

    ManagedDataSource managed = new ManagedDataSource(dataSource);
    environment.addManaged(managed);

    return managed;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:17,代码来源:Databases.java

示例9: newDataSource

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Create a new {@code DataSource}.
 * <br>
 * The lifecycle of the created instance is <strong>NOT</strong>
 * managed by baseline. To create a {@code DataSource} whose lifecycle
 * is managed, use {@link #newManagedDataSource(Environment, DatabaseConfiguration)}.
 *
 * @param database database configuration block for configuring the {@code DataSource}
 * @return valid, new {@code DataSource} instance
 */
public static DataSource newDataSource(DatabaseConfiguration database) {
    BasicDataSource dataSource = new BasicDataSource();

    // attempt to load the driver class
    dataSource.setDriverClassName(database.getDriverClass());

    // username and password
    // only sets them if the value is not null/empty
    if (!(database.getUsername() == null || database.getUsername().isEmpty())) {
        dataSource.setUsername(database.getUsername());
    }
    if (!(database.getPassword() == null || database.getPassword().isEmpty())) {
        dataSource.setPassword(database.getPassword());
    }

    // other properties
    dataSource.setUrl(database.getUrl());
    dataSource.setDefaultTransactionIsolation(database.getDefaultTransactionIsolation().getLevel());
    dataSource.setDefaultAutoCommit(database.isAutoCommit());
    dataSource.setTestOnBorrow(database.isCheckConnectionOnBorrow());
    dataSource.setTestOnReturn(database.isCheckConnectionOnReturn());
    dataSource.setMinIdle(database.getMinTotalConnections());
    dataSource.setMaxTotal(database.getMaxTotalConnections());
    dataSource.setMaxIdle(database.getMaxIdleConnections());
    dataSource.setMaxWaitMillis(database.getAcquireConnectionTimeout());
    dataSource.setDefaultQueryTimeout(database.getQueryTimeout() <= 0 ? null : database.getQueryTimeout());
    dataSource.setTestWhileIdle(database.isCheckConnectionWhenIdle());
    dataSource.setTimeBetweenEvictionRunsMillis(database.getIdleConnectionCheckInterval());
    dataSource.setMinEvictableIdleTimeMillis(database.getCloseIdleConnectionAfter());
    dataSource.setValidationQuery(database.getValidationQuery());
    dataSource.setValidationQueryTimeout((int) database.getValidationQueryTimeout());
    dataSource.setAccessToUnderlyingConnectionAllowed(false);
    dataSource.setDefaultAutoCommit(false);

    return dataSource;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:47,代码来源:Databases.java

示例10: getPool

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
public BasicDataSource getPool() {
	return pool;
}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:4,代码来源:ConnectionDB.java

示例11: findById

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
public Producto findById(String id)
{
	Connection conexion = null;
	Producto p = null;
	try
	{
		ConnectionDB pool = ConnectionDB.getInstancia();
		BasicDataSource datasource = pool.getPool();
		conexion = datasource.getConnection();
		
			
		String query = "select * from producto where idProducto = ?" ;
		
		PreparedStatement s = conexion.prepareStatement(query);
    
		s.setString(1,id);
    
		ResultSet result = s.executeQuery ();
    
		if (result.next())
		{
			p = new Producto();
			p.setId_producto(result.getInt(1));
			p.setNombre(result.getString(2));
			p.setPlataforma(result.getString(3));
			p.setCategoria(result.getString(4));
			p.setStock(result.getInt(5));
			p.setPrecio(result.getFloat(6));
			p.setFecha(result.getString(7));
			p.setDescripcion(result.getString(8));
		}
        conexion.close();
		
	}
	
	
	catch (Exception ex)
	{
		System.out.println ("Error"+ex.getMessage());
	}


	return p;
}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:45,代码来源:DAOProducto.java

示例12: canMap

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
@Override
public boolean canMap(Object resource) {
  return "org.apache.tomcat.dbcp.dbcp2.BasicDataSource".equals(resource.getClass().getName())
      && resource instanceof BasicDataSource;
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:6,代码来源:Tomcat8DbcpDatasourceAccessor.java

示例13: registerGauges

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
private static void registerGauges(final BasicDataSource dataSource) {
    MetricRegistries.getRegistry().register(MetricRegistries.name("db", dataSource.getUrl(), "used"), (Gauge<Integer>) dataSource::getNumActive);
    MetricRegistries.getRegistry().register(MetricRegistries.name("db", dataSource.getUrl(), "idle"), (Gauge<Integer>) dataSource::getNumIdle);
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:5,代码来源:Databases.java

示例14: ManagedDataSource

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param dataSource valid {@code DataSource} instance whose lifecycle should be managed by baseline
 */
@Inject
public ManagedDataSource(BasicDataSource dataSource) {
    this.dataSource = dataSource;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:10,代码来源:ManagedDataSource.java


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