Java Reference
In-Depth Information
Listing 3-23. The Class to Create the Example Users
package sample;
import sample.dao.DAO;
import sample.dao.UserDAO;
public class CreateUser {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("params required: username, password");
return;
}
String username = args[0];
String password = args[1];
try {
UserDAO userDao = new UserDAO();
System.out.println("Creating user " + username);
userDao.create(username, password);
System.out.println("Created user");
DAO.close();
} catch (AdException e) {
System.out.println(e.getMessage());
}
}
}
The CreateUser class uses the UserDAO class to create and persist an appropriate User
object. The specifics of the (two) users created are drawn from the command-line parameters
provided in the createUsers Ant task.
In Listing 3-24, we create Category objects via the CategoryDAO class—and again we draw
the specific details from the command line provided by the Ant script.
Listing 3-24. The Class to Create the Example Categories
package sample;
import sample.dao.CategoryDAO;
import sample.dao.DAO;
public class CreateCategory {
public static void main(String[] args) {
Search WWH ::




Custom Search