Basic DataSource Example : Connection Pool « Apache Common « Java





Basic DataSource Example

import java.sql.Connection;

import org.apache.commons.dbcp.BasicDataSource;

public class BasicDataSourceExample {

  public static void main(String args[]) throws Exception {

    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName("com.mysql.jdbc.Driver");
    bds.setUrl("jdbc:mysql://localhost/commons");
    bds.setUsername("root");
    bds.setPassword("");

//    bds.setInitialSize(5);

    Connection connection = bds.getConnection();

    System.err.println(connection);
    connection.close();
  }
}
           
       










BasicDataSourceExample.zip( 1,004 k)

Related examples in the same category

1.Connection Pool Basics
2.Database connection pool demo