建立一个 Derby 日历,第 1 部分: 理解 JDBC
2010-04-19 00:00:00 来源:WEB开发网同时,我还添加了构造器和 create()、update() 以及 delete() 方法的占位程序。
如果您打开了一个单独的窗口来编译这个类,可以运行 sysinfo 来设置 CLASSPATH。
接受事件信息
清单 6 显示了如何提供一种方式让用户从命令行键入事件信息。
清单 6. 接受事件信息
public class Event {
public Event(){}
public Event(int eventId) {
setId(eventId);
}
public Event(String newTitle, String newDescription,
String newRemindersTo, int eventMonth,
int eventDay, int eventYear){
create(newTitle, newDescription, newRemindersTo,
eventMonth, eventDay, eventYear);
}
...
public boolean create(String newTitle, String newDescription,
String newRemindersTo, int eventMonth,
int eventDay, int eventYear) {
setTitle(newTitle);
setDescription(newDescription);
setRemindersTo(newRemindersTo);
setEventMonth(eventMonth);
setEventDay(eventDay);
setEventYear(eventYear);
System.out.println("Creating event for " + this.getEventMonth()+
"/" + this.getEventDay() + "/" +
this.getEventYear());
System.out.println(this.getTitle());
System.out.println(this.getDescription());
System.out.println("Reminders to: " + this.getRemindersTo());
return true;
}
public boolean delete()
{
return true;
}
public boolean update(String newTitle, String newDescription,
String newRemindersTo, int newMonth, int newDay,
int newYear){
return true;
}
public static void main (String args[]){
if (args.length < 6){
System.out.println("Usage: Event <eventId> <title> "+
"<description> <remindersTo> "+
"<month> <day> <year>");
} else {
String newTitle = args[0];
String newDescription = args[1];
String newReminders = args[2];
int newMonth = Integer.parseInt(args[3]);
int newDay = Integer.parseInt(args[4]);
int newYear = Integer.parseInt(args[5]);
Event theEvent = newEvent(newtitle, newdescription,
newreminders, newmonth, newday, newyear)
}
}
}
更多精彩
赞助商链接