JDBC Connection Loader

This loader compiles the contents of the file to a Millscript DatabaseSource. A DatabaseSource is a thin wrapper for a java.sql.DataSource, from which database connections are obtained.

The first time a connection is requested, one will be obtained, stored and then supplied. The connection will kept open so that it can be reused as many times as necessary.

All subsequent times a connection is requested the cached one will be returned if it hasn't been closed, otherwise a new conection will be obtained, cached and supplied.

File Format

The format of a jdbcconn file is as follows:

data.source.name = The name of this DataSource
host             = ahost.somewhere.org
port             = 5432
username         = testuser
password         = testpassword
db.name          = test

        

The port and max.connections lines are optional. If they are excluded the underlying implementation will choose defaults. All other lines are mandatory.

Key Value Description
data.source.name A name for this data source
host The hostname of the database server. e.g. localhost or 192.168.1.1
port The TCP/IP port which the database server is listening on. If specify this parameter and you give the value 0, the implementation default will be used.
username The username to use when establishing a connection to the database
password The password to use when establishing a connection to the database, with the given username
db.name The name of the database to connect to. e.g. mydatabase

Use

  1. Create an jdbcconn file in your inventory, containing all the required properties, as detailed in the file format. e.g Lets assume you create a file called localhost.jdbcconn.
  2. To use the connection within a script, we just have to refer to the name of the jdbcconn file, e.g.
    localhost
                
    and this will load the connection for us.

Notes

  • If you try to get more than the maximum number of connections(max.connections) from a DataSource, the getConnection call will block until a Connection becomes available. Hence the script would hang.