Reputation: 363
I'm trying to create an ANT task that takes some database properties and executes a MYSQL script. For a specific database, it's working fine, and what I have is the following:
A configurable properties file:
sql.driver=com.mysql.jdbc.Driver
sql.url=jdbc:mysql://127.0.0.1:3306/
sql.user=admin
sql.pass=admin
And the build.xml ant file:
<target name="rebuild-database">
<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}">
<transaction src="db/rebuild.sql"/>
<classpath>
<path refid="project.class.path"/>
</classpath>
</sql>
</target>
Now, that works fine. The sql script rebuilds the database. However, I want this database name to be also configurable. I know you can append the database name after the sql.url property, but here's the catch, my rebuild.sql file has to drop the database if it exists and rebuild it. It looks like this:
rebuild.sql
DROP DATABASE IF EXISTS `client_database`;
CREATE DATABASE `client_database`
USE `client_database`;
CREATE TABLE `Customer` (
etc...
So my problem is, right now client_database
is hardcoded, but I need it to be a configurable name in the properties file. How could I manage to pass around this name into the sql script and execute those 3 first statements?
Upvotes: 3
Views: 5496
Reputation: 8941
You can
Upvotes: 2