I want to pass parameters to mysql source file from ant script.
Here is my ant script.
<target name="post"
description="do post processing command: -Dusername=db-username -Dpassword=db-password -Ddb=database-name post">
<echo message="Doing Post processing..."></echo>
<sql driver="org.gjt.mm.mysql.Driver" url="jdbc:mysql://${dburl}/kom?autoReconnect=true"
userid="userid" password="password" print="yes" classpathref="class-path"
src="${sql-dir}/${post-sql}" output="logs/ant-sql.log">
</sql>
</target>
In the sql file, I have to do the following..
CREATE DATABASE IF NOT EXISTS $(dbname);
use $(dbname);
-- create table posts
-- a lot of create and insert statemenst.
I can't use mysql console or any other utilities.
Can somebody tell me how to do this ?
Solution
I moved the use $(dbname) from sql file to ant script.
<target name="post"
description="do post processing command: -Dusername=db-username -Dpassword=db-password -Ddb=database-name post">
<echo message="Doing Post processing..."></echo>
<sql driver="org.gjt.mm.mysql.Driver" url="jdbc:mysql://${dburl}/kom?autoReconnect=true"
userid="root" password="tintin" print="yes" classpathref="class-path"
src="${sql-dir}/${post-sql}" output="logs/ant-sql.log">
use ${dbname};
</sql>
</target>
It works as a temporary solution.