ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Jackson" <foamd...@gmail.com>
Subject Re: 答复: how to load a bunch data from a txt file, and ant sql call these data
Date Thu, 20 Mar 2008 02:07:00 GMT
Hi,

>  I have a ant sql statement
>
>
>  <target name="insertData">
>                 <sql driver="${jdbcdriver}" url="${dburl}/BillPay"
>  userid="${userid}" password="${password}"
>                         print="yes" onerror="continue"
>  output="${tmp.dir}/dbModification.txt">
>                         <transaction> INSERT INTO Payment (RefNumber,
>  VAN, Amount, OptCode, VendorID,
>                                 PriorRefNumber, TransactionTS,
>  IsProcessed) VALUES
>
>  ('6569998989','2131213','1131',2031,232,'7898', { fn NOW() },1);
>  </transaction>
>                         <transaction> INSERT INTO Payment (RefNumber,
>  VAN, Amount, OptCode, VendorID,
>                                 PriorRefNumber, TransactionTS,
>  IsProcessed) VALUES
>
>  ('9565689232323','21313213','1131',2031,232,'7898', { fn NOW() },1);
>  </transaction>
>                 </sql>
>
>  Here there are 2 sql statement to insert. But I have more than 100 data
>  put in txt file.
>
>  Like this
>  '1569998989','2131213','1131',2031,232,'7898', { fn NOW() },
>  '2569998989','2131213','1131',2031,232,'7898', { fn NOW() },
>  '3569998989','2131213','1131',2031,232,'7898', { fn NOW() },
>
>
>  Could you tell me How can load these data from a txt file. And using
>  loop to insert these data into database. Which means dynamically.
>  So I don't need to put  more thant 100 sql statement in the ant build
>  file.

Ant doesn't usually deal with 'loops' in the usual sense (imperative
programming style). In ant it's more normal to define a dataset and
perform the same operation for the entire set - not sure if I
explained that properly (morning coffee hasn't kicked in)

Here are a couple of suggestions:
- checkout dbunit it has good ant integration and makes this kind of
db interaction easy
- read the ant manual http://ant.apache.org/manual/CoreTasks/sql.html
<sql
    driver="org.database.jdbcDriver"
    url="jdbc:database-url"
    userid="sa"
    password="pass"
    src="data.sql"
/>

Please be aware that we are all busy, and this is not an uncommon
thing to want to do so there's a good chance that someone has an
example or has asked the question before.

In the future if you could try:
- Check the ant manual (see if there's a task that matches what you want to do)
- Read the mailing list archives (google search for them or try
http://marc.info/)
- Finally ask on the users list

You may feel that it was rude to ask you to read the standard 'How to
ask for help page', but really there's a good reason that page exists
and especially with open source software where everyone is a
volunteer.

Thanks,
Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message