More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Ant Script to Insert Data in Mysql Table

                         

This example illustrates how to insert data in table through the build.xml file by simply running the ant command. In this build.xml file, we are using 4 property elements for connectivity from database. The first element <property name="sql.driver"> is used to connect from the sql driver. The second element <property name="sql.url"> is used to define the database url and database name. The third element <property name="sql.user"> is used to define user name of the database. The fourth element <property name="sql.pass"> is used to define the password name of the database. 
               

In this build.xml file, <target name="createTables"> is used to execute the query which is in the client.sql and project.sql file and <target name"insertData"> is used to execute the query which is in the insertclient.sql and insertproject.sql file. The source code of the build.xml file is as follows: 

 

<project name="MysqlCreateTableAndInsertData" basedir="." default="insertData">

  <property name="sql.driver" value="org.gjt.mm.mysql.Driver"/>
  <property name="sql.url" value="jdbc:mysql://192.168.10.211/test"/>
  <property name="sql.user" value="sandeep"/>
  <property name="sql.pass" value="sandeep"/>

  <target name="createTables" >
    <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
      <transaction src="client.sql"/>
      <transaction src="project.sql"/>
    </sql>
  </target>

  <target name="insertData" depends="createTables">
    <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
      <transaction src="insertclient.sql"/>
      <transaction src="insertproject.sql"/>
    </sql>
  </target>

</project>

client.sql

create table client (
        client_id int not null auto_increment primary key,
        client_name text not null
);

project.sql

create table project (
        project_id int not null auto_increment primary key,
        project_name text not null
);

insertclient.sql

INSERT INTO client (client_name) VALUES ("Galanthus nivalis");
INSERT INTO client (client_name) VALUES ("Narcissus pseudonarcissus");
INSERT INTO client (client_name) VALUES ("Narcissus poeticus var. recurvus");
INSERT INTO client (client_name) VALUES ("Leucojum vernum");
INSERT INTO client (client_name) VALUES ("Iris pseudacorus");
INSERT INTO client (client_name) VALUES ("Crocus tommasinianus");
INSERT INTO client (client_name) VALUES ("Colchicum autumnale");
INSERT INTO client (client_name) VALUES ("Hyacinthoides non-scripta");
INSERT INTO client (client_name) VALUES ("Erythronium dens-canis");
INSERT INTO client (client_name) VALUES ("Fritillaria meleagris");
INSERT INTO client (client_name) VALUES ("Cyclamen coum");
INSERT INTO client (client_name) VALUES ("Tulipa turkestanica");
INSERT INTO client (client_name) VALUES ("Ranunculus ficaria");

insertproject.sql

INSERT INTO project (project_name) VALUES ("codingdiary.com");
INSERT INTO project (project_name) VALUES ("roseindia.net");
INSERT INTO project (project_name) VALUES ("allcooljobs.com");
INSERT INTO project (project_name) VALUES ("huntarticles.com");
INSERT INTO project (project_name) VALUES ("onlinefreetrading.com");
INSERT INTO project (project_name) VALUES ("allcoolloans.com");
INSERT INTO project (project_name) VALUES ("newstrackindia.com");
INSERT INTO project (project_name) VALUES ("artsandlitreture.com");
INSERT INTO project (project_name) VALUES ("javajazzup.com");
INSERT INTO project (project_name) VALUES ("whitecollers.com");
INSERT INTO project (project_name) VALUES ("singlepane.com");
INSERT INTO project (project_name) VALUES ("ilikeyoutube.com");
INSERT INTO project (project_name) VALUES ("fake.com");

Create the all client.sql, project.sql, insertclient.sql, insertproject.sql files parallel of the build.xml file and simply run the build.xml file with ant command in the appropriate path on command prompt. If the program executes successfully, then the following output will be displayed.


Download Source Code

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Join and Excel yourself with our Online instructor led training sessions
Training Courses
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.