Description: Normally, you can simply work with the interfaces for javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, and javax.sql.XADataSource, as shown in the following examples.
Keywords: properties, DataSource, getting

# Getting a DataSource

Normally, you can simply work with the interfaces for javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, and javax.sql.XADataSource, as shown in the following examples.

    // If your application is running on the Java SE 6 platform,
    // and if you would like to call DataSource methods specific
    // to the JDBC 4 API (for example, isWrapperFor), use the
    // JDBC 4 variants of these classes:
    //
    //   org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource40
    //   org.apache.derby.jdbc.EmbeddedDataSource40
    //   org.apache.derby.jdbc.EmbeddedXADataSource40
    //
    import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
    import org.apache.derby.jdbc.EmbeddedDataSource;
    import org.apache.derby.jdbc.EmbeddedXADataSource;

    javax.sql.ConnectionPoolDataSource cpds = new EmbeddedConnectionPoolDataSource();
    javax.sql.DataSource ds = new EmbeddedDataSource();
    javax.sql.XADataSource xads = new EmbeddedXADataSource();

Derby provides six properties for a DataSource. These properties are in org.apache.derby.jdbc.EmbeddedDataSource. They are:

- DatabaseName

  This mandatory property must be set. It identifies which database to access. To access a database named wombat located at /local1/db/wombat, call setDatabaseName("/local1/db/wombat") on the data source object.

- CreateDatabase

  Optional. Sets a property to create a database the next time the getConnection method of a data source object is called. The string createString is always "create" (or possibly null). (Use the method setDatabaseName() to define the name of the database.)

- ShutdownDatabase

  Optional. Sets a property to shut down a database. The string shutDownString is always "shutdown" (or possibly null). Shuts down the database the next time the getConnection method of a data source object is called.

- DataSourceName

  Optional. Name for ConnectionPoolDataSource or XADataSource. Not used by the data source object. Used for informational purposes only.

- Description

  Optional. Description of the data source. Not used by the data source object. Used for informational purposes only.

- connectionAttributes

  Optional. Connection attributes specific to Derby. See the Java DB Reference Manual for a more information about the attributes.

Parent topic: Using Derby as a J2EE resource manager
Related concepts
Shutting down or creating a database
Related reference
Classes that pertain to resource managers