temp temp wrote:
I trying to execute small script using ant , here is the script
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET MARKUP HTML OFF
SET ESCAPE \
SPOOL DELETEME.SQL
select 'drop table ', table_name, 'cascade constraints \;' from user_tables
how to run this script using ant sql task
Stick it inline in the task, set up the classpath with the right JDBC
drivers.
From the source of Ant in Action, two targets to set up the classpath
with mysql and define new sql tasks all set up as the right users
<target name="mysql-init" depends="ivy-resolve"
xmlns:ext="http://antbook.org/d1/ext" >
<ivy:cachepath pathid="sql.classpath" conf="sql" />
<property name="mysql.root.pass" value=""/>
<property name="mysql.diary.pass" value="secret"/>
<presetdef name="mysql-admin"
uri="http://antbook.org/d1/ext">
<sql driver="com.mysql.jdbc.Driver"
classpathref="sql.classpath"
userid="root"
password="${mysql.root.pass}"
print="true"
url="jdbc:mysql://localhost/mysql"
expandProperties="true"/>
</presetdef>
<presetdef name="mysql"
uri="http://antbook.org/d1/ext">
<ext:mysql-admin
userid="diary"
password="${mysql.diary.pass}"
url="jdbc:mysql://localhost/diary"/>
</presetdef>
</target>
Followed up by some operations
<target name="mysql-drop-db" depends="mysql-init"
description="create the database and account">
<ext:mysql-admin onerror="continue">
DROP DATABASE diary;
</ext:mysql-admin>
</target>
<target name="mysql-create-db"
depends="mysql-init,mysql-drop-db"
description="create the database and account">
<ext:mysql-admin>
CREATE DATABASE diary;
GRANT ALL PRIVILEGES ON diary.* TO 'diary'@'localhost';
SET PASSWORD FOR 'diary'@'localhost' =
PASSWORD('${mysql.diary.pass}');
</ext:mysql-admin>
</target>
<target name="mysql-create-events" depends="mysql-init"
description="create the event table">
<ext:mysql>
CREATE TABLE EVENTS (
EVENT_ID varchar(64) not null,
EVENT_NAME varchar(255) not null,
EVENT_DATE timestamp not null,
EVENT_VERSION integer,
EVENT_LASTMODIFIED timestamp,
EVENT_TEXT varchar(8192),
primary key (EVENT_ID));
</ext:mysql>
</target>
<target name="mysql-create-events-file" depends="mysql-init">
<ext:mysql>
<transaction src="config/deploy/sql/create_event_table.sql" />
</ext:mysql>
</target>
<target name="mysql-list-events" depends="mysql-init"
description="list all events in the system">
<ext:mysql>
select * from EVENTS;
</ext:mysql>
</target>
Nothing to it, once you have the JDBC drivers and paths set up
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]