Sql

Description

Executes a series of sql statement via JDBC to a database. Statements can either be read in from a text file using the src attribute or from between the enclosing sql tags.

Multiple statements can be set and each statement is delimited from the next use a semi-colon. Individual lines within the statements can be commented using either -- or // at the start of the line.

The auto-commit attribute specifies whether auto commit should be turned on or off whilst executing the statements. If auto-commit is turned on each statement will be executed and commited. If it is turned off the statements will all be executed as one transaction.

Parameters

Attribute Description Required
driver Class name of the jdbc driver Yes
url Database connection url Yes
userid Database user name Yes
password Database password Yes
src File containing sql statements Yes, unless statements enclosed within tags
autocommit Auto commit flag for database connection (default false) No, default "false"

Examples

<sql driver="org.database.jdbcDriver" url="jdbc:database-url" userid="sa" password="pass" src="data.sql" />

Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the sql statements contained within the file data.sql

<sql
    driver="org.database.jdbcDriver"
    url="jdbc:database-url"
    userid="sa"
    password="pass"
    >
insert
into table some_table
values(1,2,3,4);

truncate table some_other_table;
</sql>

Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the two sql statements inserting data into some_table and truncating some_other_table