Hi,
Here is code that connects to MS SQL Server database table called appointments and reads the data for events stored there. It creates MindFusion.Scheduling Appointment instances and renders a weekly calendar with them:
private void readAppointments() throws ClassNotFoundException
{
Connection conn = null;
PreparedStatement pst;
try {
// db parameters
String sql = "SELECT start_time, end_time, header_text, recurrence_interval, description FROM appointments";
String userName = "mindfusion";
String password = "mf1234";
String url = "jdbc:sqlserver://DESKTOP-NV9S0TU\\SQLEXPRESS;databaseName=bookings;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, userName, password);
pst = conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
System.out.println(rs.getDate("start_time").toString());
Date start = rs.getDate("start_time");
Date end = rs.getDate("end_time");
String itemText = rs.getString("header_text");
String description = rs.getString("header_text");
int recurrInterval = rs.getInt("recurrence_interval");
Appointment appointment = new Appointment();
appointment.setStartTime(new DateTime(start));
appointment.setEndTime(new DateTime(end));
appointment.setHeaderText(itemText);
appointment.setDescriptionText(description);
calendar.getSchedule().getItems().add(appointment);
}
} catch(SQLException e) {
System.out.println(e.getMessage());
} finally {
try{
if(conn != null)
conn.close();
}catch(SQLException ex){
System.out.println(ex.getMessage());
}
}
}
For your convenience I have taken a screenshot of the DB table with the data: