Package org.apache.commons.dbcp

Examples of org.apache.commons.dbcp.BasicDataSource


  }

  // public Connection getConnection() throws SQLException
  private Connection getConnection() throws SQLException
  {
      ds = new BasicDataSource();
      ds.setDriverClassName(driver);
      ds.setUsername(user);
      ds.setPassword(pass);
      ds.setUrl(connurl);
View Full Code Here


    /**
     * Closes the DataSource.
     */
    public final void shutdownDataSource(DataSource ds) throws SQLException {
        // TODO who call me.
        BasicDataSource bds = (BasicDataSource) ds;
        bds.close();
    }
View Full Code Here

        super();
    }

    public DataSource setupDataSource(String connectURI) {
        // creates DataSource
        BasicDataSource ds = new BasicDataSource();

        // for debugging.
        if(Settings.isLoggingEnabled) {
            ds.setAccessToUnderlyingConnectionAllowed(true);
        }

        ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind")));

        // sets up DataSource
        ds.setUrl(connectURI);
        final String dbuser = Settings.get("xbird.db.user");
        final String dbpasswd = Settings.get("xbird.db.passwd");
        if(dbuser != null && dbuser.length() != 0) {
            ds.setUsername(dbuser);
            ds.setPassword(dbpasswd);
        }

        // addtinal settings.
        final String maxactive = Settings.get("xbird.db.pool.maxactive");
        if(maxactive != null)
            ds.setMaxActive(Integer.parseInt(maxactive));

        final String maxidle = Settings.get("xbird.db.pool.maxidle");
        if(maxidle != null)
            ds.setMaxIdle(Integer.parseInt(maxidle));

        final String maxwait = Settings.get("xbird.db.pool.maxwait");
        ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait));

        ds.setDefaultAutoCommit(true);
        //ds.setDefaultReadOnly(false);

        final String initialsize = Settings.get("xbird.db.pool.initialsize");
        ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE
                : Integer.parseInt(initialsize));

        // sets up for PreparedStatements.
        ds.setPoolPreparedStatements(true);

        final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size");
        ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS
                : Integer.parseInt(maxOpenPreparedStatements));

        return ds;
    }
View Full Code Here

*/
public class DbcpDatasourceAccessor implements DatasourceAccessor {
    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.getMaxActive());
            dataSourceInfo.setJdbcURL(source.getUrl());
            dataSourceInfo.setUsername(source.getUsername());
            dataSourceInfo.setResettable(false);
        }
        return dataSourceInfo;
    }
View Full Code Here

  private UserBookmarkTimeline action;
  private BasicDataSource dataSource;
  private GnizrDao gnizrDao;
 
  public TestUserBookmarkTimeline(){
    dataSource = new BasicDataSource();
    dataSource.setUsername("gnizr");
    dataSource.setPassword("gnizr");
    dataSource.setUrl("jdbc:mysql://localhost/gnizr_test");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
   
View Full Code Here

  private DataSource lookupDataSource(String url, String user, String password)
    throws NamingException
  {
    if (url.startsWith("jdbc:")) {
      BasicDataSource ds = new BasicDataSource();
      ds.setUrl(url);
      ds.setUsername(user);
      ds.setPassword(password);
      setBasicDataSource(ds);
      return ds;
    }
    return (DataSource)new InitialContext().lookup(url);
  }
View Full Code Here

      url.append("&");
      url.append(enc(e.getKey()));
      url.append("=");
      url.append(enc(e.getValue()));
    }
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(url.toString());
    if (user != null) {
      ds.setUsername(user);
    }
    else {
      ds.setUsername(System.getProperty("user.name"));
    }
    if (password != null) {
      ds.setPassword(password);
    }
    MySqlConnectionFactory factory = new MySqlConnectionFactory();
    factory.setSail(this);
    factory.setDataSource(ds);
    setBasicDataSource(ds);
View Full Code Here

    String gnizrFullname = prpt.getProperty("gnizr.import.fullname");
    String deliUser = prpt.getProperty("gnizr.import.delicious.user");
    String deliPassword = prpt
        .getProperty("gnizr.import.delicious.password");

    BasicDataSource datasource = new BasicDataSource();
    datasource.setDriverClassName(dbdrv);
    datasource.setUrl(dbUrl);
    datasource.setUsername(dbUser);
    datasource.setPassword(dbPass);

    GnizrDao gnizrDao = GnizrDao.getInstance(datasource);

    UserManager userManager = new UserManager(gnizrDao);
    BookmarkManager bookmarkManager = new BookmarkManager(gnizrDao);
View Full Code Here

    init();
  }

  private void init() {
    if (dataSource == null) {
      dataSource = new BasicDataSource();
      dataSource.setUsername("gnizr");
      dataSource.setPassword("gnizr");
      dataSource.setUrl("jdbc:mysql://localhost/gnizr_test");
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.addConnectionProperty("characterEncoding", "UTF-8");
View Full Code Here

*/
public class MySQLDBExport {
 
  public static void main(String[] args) throws Exception
   
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUsername("gnizr");
    dataSource.setPassword("gnizr");
    dataSource.setUrl("jdbc:mysql://localhost/gnizr_db");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
   
    IDatabaseConnection dc = new DatabaseConnection(dataSource.getConnection());
    DatabaseConfig config = dc.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new MySqlDataTypeFactory());

        // full database export
View Full Code Here

TOP

Related Classes of org.apache.commons.dbcp.BasicDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.