Creating Database Tables Using ANT

By: Sri Ganesh Emailed: 1766 times Printed: 2513 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

First, you can use a properties file to feed ANT, which has a simple sql target. Create a simple properties file, such as the one below:

 # Database properties are in derby.properties
 db.delimiter=;
 db.root=${javaee.home}/derby
 db.driver=org.apache.derby.jdbc.ClientDriver
 db.datasource=org.apache.derby.jdbc.ClientDataSource
 db.host=localhost
 db.port=1527
 db.sid=sun-appserv-samples
 db.url=jdbc:derby://${db.host}:${db.port}/${db.sid};create=true;
 db.user=APP
 db.pwd=APP 
 

Next, create a build.xml file that includes targets for compiling the Java code as well as a target similar to the following:

 <target name="create-db_common" depends="init,start-db,delete-db" 
               description="Create database tables and populate database.">
 -
    <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" 
         password="${db.password}" classpathref="db.classpath" 
                 delimiter="${db.delimiter}" autocommit="false" onerror="abort">
 <transaction src="
          {javaee.tutorial.home}/examples/common/sql/${db.vendor}/tutorial.sql"/>
 </sql>
 </target>

The tutorial.sql file can contain the commands to create the tables and, possibly, populate the tables if need be, such as the example below:

 create table COFFEES(cof_name varchar32, price int, sup_id int,
 price float, sales int, total int);

The ';' matches the db.delimiter property.

NetBeans contains everything you need, including the Java DB and ANT. You can Download NetBeans from here.


JDBC Home | All JDBC Tutorials | Latest JDBC Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sri Ganesh
public, private, protected modifiers in Java
Creating Database Tables Using ANT

More Tutorials in JDBC
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
Import TEXT to TABLE in MSSQL
What is Referential Integrity in databases?
Handling CSV in Stored Procedures
setSavepoint and releaseSavepoint Example in Java
Calling a Stored Procedure from JDBC in Java
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Creating Database Connection Pool in Tomcat 5.0 and Tomcat 5.5 for MySQL and Java
JDBC Basics and JDBC Components
SELECT Statements
WHERE Clauses in SQL
Joins example in SQL
Common SQL Commands
Result Sets, Cursors and Transactions in SQL
Stored Procedures example in SQL

More Latest News
Most Viewed Articles (in JDBC )
Creating Database Tables Using ANT
Using JDBC to connect to MySQL from Java Program
What is JDBC?
JDBC Components
JDBC Architecture
The Structure of JDBC
A simple JDBC application sample code
How connection pooling works in Java and JDBC
Using JDBC to extract data from a database and output to an XML document
What is the ACID principal?
Using Transactions in JDBC
Data Access Technologies in Java
JDBC and Tomcat context settings
Creating Database Connection Pool in Tomcat 5.0 and Tomcat 5.5 for MySQL and Java
JDBC Basics and JDBC Components
Most Emailed Articles (in JDBC)
What is JDBC?
WHERE Clauses in SQL
Result Sets, Cursors and Transactions in SQL
JDBC Architecture
The Structure of JDBC
JDBC Basics and JDBC Components
Stored Procedures example in SQL
Getting Started with JDBC
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
What is Referential Integrity in databases?
Using JDBC to connect to MySQL from Java Program
JDBC Components
Data Access Technologies in Java
Joins example in SQL
Common SQL Commands