建立一个 Derby 日历,第 2 部分: 嵌入选项(下)
2010-04-19 00:00:00 来源:WEB开发网这里仅仅在调用方法时传递用户名和口令,并根据需要继续传递。
应用程序以同样的方式处理提示消息,如 清单 16 所示。
清单 16. Reminders 和用户信息
...
public void sendAllReminders(int eventMonth,
int eventDay, int eventYear,
String username, String password) {
try {
Class.forName(driver).newInstance();
Connection conn = null;
conn = DriverManager.getConnection(
"jdbc:derby://localhost:1527/calendar;user="+
username+";password="+password);
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM Event "+
"where eventMonth="+eventMonth+
" and eventDay="+eventDay+" and "+
"eventYear="+eventYear);
while (rs.next()) {
String title = rs.getString(2);
String description = rs.getString(3);
String remindersTo = rs.getString(4);
String dateString = rs.getString(5)+"/"
+rs.getString(6)+"/"+rs.getString(7);
sendMessage(remindersTo, title, description,
dateString);
}
rs.close();
s.close();
conn.close();
try {
DriverManager.getConnection(
"jdbc:derby:;shutdown=true");
} catch (SQLException se) { }
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main (String args[]){
Reminder rem = new Reminder();
rem.sendMessage("nchase@earthlink.net", "Test event",
"Test description", "8/26/2005");
rem.sendAllReminders(2,27,2006, args[0], args[1]);
}
}
更多精彩
赞助商链接