File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes how to access a datasource from ant? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "how to access a datasource from ant?" Watch "how to access a datasource from ant?" New topic

how to access a datasource from ant?

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I've got an ant build file with a "db" target that creates a fresh new database. This currently uses a sql task to drop and create tables. The connection is made by specifying the driver, url, userid, and password. Works fine. However now I need to modify this to use a datasource instead. I have the JNDI name of the datasource, but the sql task doesn't seem to support connecting via JNDI. Am I missing something here? Is there some other way in an ant script to connect to a datasource and execute some arbitrary SQL statements?

I could write a Java class that opens the connection I suppose. But it seems like I wouldn't be the first person to want to do something like this, so I suspect there's another way. Anyone?

Ah, with a bit more research I see that here Roseanne mentions having the same problem a few years ago and writing a custom task. Roseanne, is that code available anywhere? Or has any other solution arisen since then?

"I'm not back." - Bill Harding, Twister
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
All right, I was able to get hold of traditional JDBC connection info I can use instead: URL, username, password. Seems odd though that using a datasource isn't supported here. Oh well.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I might be able to find the code, but probably it will not be very useful for you, since I wrote a customized encrypted JNDI, and it was in a huge system, with a lot configuration files.

However, I will try to have a look tonight. It is good for me to review what I did too. If I can extract something simple and useful, I will let you have it.
I agree. Here's the link:
subject: how to access a datasource from ant?
Similar Threads
Howto Oracle 9i Connection Pooling with Sun One application Server 7
looking for suggestions on better DAO design
SOS, "IO exception: The Network Adaptor could not establish the connection." ?
How to make a data source connection without writing a User name & Password and the -ds.xml file
getting errors while running duke's bank application