Java Reference
In-Depth Information
if (args.length != 1) {
System.out.println("param required: categoryTitle");
return;
}
CategoryDAO categories = new CategoryDAO();
String title = args[0];
try {
System.out.println("Creating category " + title);
categories.create(title);
System.out.println("Created category");
DAO.close();
} catch (AdException e) {
System.out.println(e.getMessage());
}
}
}
The code in Listing 3-25 allows us to create an advert for a preexisting user in a pre-
existing category. Note our use of UserDAO and CategoryDAO to obtain User and Category
objects from the database. As with the user and category, the advert details are supplied
by the Ant task.
Listing 3-25. The Class to Create the Example Adverts
package sample;
import sample.dao.AdvertDAO;
import sample.dao.CategoryDAO;
import sample.dao.DAO;
import sample.dao.UserDAO;
import sample.entity.Advert;
import sample.entity.Category;
import sample.entity.User;
public class PostAdvert {
public static void main(String[] args) {
if (args.length != 4) {
System.out.println("params required: username, categoryTitle, title, message");
return;
}
Search WWH ::




Custom Search