McDonald NHL Power Ratings – February 7, 2021

Hockey playerThis week’s McDonald NHL Power Ratings are out a little later than usual, but here they are!

Boston had a strong week (3-0-0 against the Capitals and Flyers) to move into first in the rankings.  Tampa Bay also went 3-0-0, but because they played against weaker teams, their rating didn’t increase as much as Boston’s, so they’ve dropped into 2nd place.  The Leafs cracked the top 5 for the first time this year, possibly for the first time since I’ve done the ratings.  Other big movers included Winnipeg (12th, 2-0-1, up 12 points), Arizona (16th, 2-1-0, up 14 points), and the Rangers (19th, 2-0-0, up 15 points).

Boston and Tampa Bay are still the favourites to win the Stanley Cup.  We give both teams a 9% chance of winning.  Ottawa and Detroit are the longshots, at only a 7% and 4% chance of even making the playoffs.

On the downside, big droppers were Washington (9th, 0-3-0, down 24 points), Vancouver (26th, 0-4-0, down 23 points), and Los Angeles (27th, 0-3-0, down 19 points).

The top 5

1. Boston Bruins (1567, 17)

Record: 8-1-2, 1st in East Division

Chances of: 

  • Making the playoffs: 90% (13)
  • Winning the President’s Trophy: 16% (8)
  • Winning the Stanley Cup: 9% (2)

Last week: 3-0-0

  • February 1: Won 5-3 @ Washington Capitals (9th, 1516)
  • February 3: Won in OT 4-3 @ Philadelphia Flyers (4th, 1545)
  • February 5: Won 2-1 @ Philadelphia Flyers (4th, 1545)

Next week:

  • February 10: @ New York Rangers (19th, 1494)
  • February 12: @ New York Rangers (19th, 1494)
  • February 13: @ New York Islanders (14th, 1503)

2. Tampa Bay Lightning 1 (1563, 13)

Record: 7-1-1, 1st in Central Division

Chances of: 

  • Making the playoffs: 88% (10)
  • Winning the President’s Trophy: 16% (6)
  • Winning the Stanley Cup: 9% (2)

Last week: 3-0-0

  • February 1: Won 5-2 vs. Nashville Predators (24th, 1477)
  • February 3: Won 5-1 vs. Detroit Red Wings (31th, 1405)
  • February 5: Won 3-1 vs. Detroit Red Wings (31th, 1405)

Next week:

  • February 8: @ Nashville Predators (24th, 1477)
  • February 9: @ Nashville Predators (24th, 1477)
  • February 11: @ Florida Panthers (13th, 1508)
  • February 13: @ Florida Panthers (13th, 1508)

3. Colorado Avalanche (1552, 6)

Record: 7-3-1, 2nd in West Division

Chances of: 

  • Making the playoffs: 82% (5)
  • Winning the President’s Trophy: 7% (1)
  • Winning the Stanley Cup: 7%

Last week: 1-0-0

  • February 2: Won 2-1 vs. Minnesota Wild (21th, 1489)
  • February 4: Postponed vs. Minnesota Wild (21th, 1489)
  • February 6: Postponed @ St. Louis Blues (7th, 1530)
  • February 7: Postponed @ St. Louis Blues (7th, 1530)

Next week:

  • February 9: vs. Arizona Coyotes (16th, 1500)
  • February 11: vs. Arizona Coyotes (16th, 1500)
  • February 14: @ Vegas Golden Knights (6th, 1543)

4 (tie). Philadelphia Flyers 1 (1545, 1)

Record: 8-3-2, 2nd in East Division

Chances of: 

  • Making the playoffs: 79%
  • Winning the President’s Trophy: 6% (2)
  • Winning the Stanley Cup: 6%

Last week: 1-1-1

  • February 3: Lost in OT 4-3 vs. Boston Bruins (1st, 1567)
  • February 5: Lost 2-1 vs. Boston Bruins (1st, 1567)
  • February 7: Won 7-4 @ Washington Capitals (9th, 1516)

Next week:

  • February 9: @ Washington Capitals (9th, 1516)
  • February 11: vs. New Jersey Devils (17th, 1497)
  • February 13: vs. New Jersey Devils (17th, 1497)
  • February 14: @ New York Rangers (19th, 1494)

4 (tie). Toronto Maple Leafs 3 (1545, 11)

Record: 9-2-1, 1st in North Division

Chances of: 

  • Making the playoffs: 93% (7)
  • Winning the President’s Trophy: 13% (4)
  • Winning the Stanley Cup: 7% (1)

Last week: 2-0-0

  • February 4: Won 7-3 vs. Vancouver Canucks (26th, 1470)
  • February 6: Won 5-1 vs. Vancouver Canucks (26th, 1470)

Next week:

  • February 8: vs. Vancouver Canucks (26th, 1470)
  • February 10: @ Montreal Canadiens (10th, 1515)
  • February 13: vs. Montreal Canadiens (10th, 1515)

Overall Ratings

 1       Boston Bruins                 1567 (17)
 2       Tampa Bay Lightning (1)      1563 (13)
 3       Colorado Avalanche            1552 (6)
 4 (tie) Philadelphia Flyers (1)      1545 (1)
 4 (tie) Toronto Maple Leafs (3)      1545 (11)
 6       Vegas Golden Knights (2)     1543 (10)
 7       St. Louis Blues (2)          1530 (14)
 8       Carolina Hurricanes (1)      1518 (1)
 9       Washington Capitals (3)      1516 (24)
10 (tie) Dallas Stars                  1515
10 (tie) Montreal Canadiens (3)       1515 (9)
12       Winnipeg Jets (3)            1513 (12)
13       Florida Panthers (2)         1508 (6)
14       New York Islanders (2)       1503 (6)
15       Columbus Blue Jackets (3)    1501 (9)
16       Arizona Coyotes (7)          1500 (14)
17 (tie) Calgary Flames (3)           1497 (5)
17 (tie) New Jersey Devils (1)        1497
19       New York Rangers (6)         1494 (15)
20       Edmonton Oilers               1492 (2)
21       Minnesota Wild (3)           1489 (6)
22       Chicago Blackhawks (3)       1488 (9)
23       Pittsburgh Penguins (5)      1482 (13)
24       Nashville Predators (2)      1477 (10)
25       Anaheim Ducks (2)            1474 (7)
26       Vancouver Canucks (5)        1470 (23)
27       Los Angeles Kings (3)        1464 (19)
28       San Jose Sharks               1463 (2)
29       Buffalo Sabres (1)           1461
30       Ottawa Senators               1423 (2)
31       Detroit Red Wings             1405 (3)

Chances of Winning Division

Central Division

 1       Tampa Bay Lightning           43% (14)
 2       Carolina Hurricanes (1)      19%
 3       Florida Panthers (1)         15% (6)
 4       Dallas Stars                  13% (2)
 5 (tie) Chicago Blackhawks (2)       4% (1)
 5 (tie) Columbus Blue Jackets         4% (4)
 7       Nashville Predators (1)      2% (3)
 8       Detroit Red Wings             <1%

East Division

 1       Boston Bruins (1)            48% (22)
 2       Philadelphia Flyers           22% (4)
 3       Washington Capitals (2)      10% (17)
 4       New Jersey Devils (1)        6%
 5       New York Islanders (1)       5% (1)
 6       New York Rangers (1)         4% (2)
 7       Pittsburgh Penguins (3)      3% (4)
 8       Buffalo Sabres (1)           2%

West Division

 1       Vegas Golden Knights (1)     36% (10)
 2       Colorado Avalanche (1)       29% (4)
 3       St. Louis Blues (2)          17% (11)
 4 (tie) Arizona Coyotes (2)          6% (2)
 4 (tie) Minnesota Wild                6% (2)
 6       Anaheim Ducks (1)            3% (1)
 7       San Jose Sharks               2%
 8       Los Angeles Kings (3)        1% (4)

North Division

 1       Toronto Maple Leafs           45% (9)
 2       Montreal Canadiens            25% (2)
 3       Winnipeg Jets                 18% (4)
 4       Calgary Flames                7% (4)
 5       Edmonton Oilers (1)          4% (2)
 6       Vancouver Canucks (1)        1% (8)
 7       Ottawa Senators               <1%

Making the Playoffs

Central Division

 1       Tampa Bay Lightning           88% (10)
 2       Carolina Hurricanes (1)      72% (3)
 3       Florida Panthers (1)         65% (5)
 4       Dallas Stars                  62% (1)
 5 (tie) Chicago Blackhawks (2)       39% (10)
 5 (tie) Columbus Blue Jackets         39% (11)
 7       Nashville Predators (1)      29% (8)
 8       Detroit Red Wings             4%

East Division

 1       Boston Bruins (2)            90% (13)
 2       Philadelphia Flyers (1)      79%
 3       Washington Capitals (1)      57% (21)
 4 (tie) New York Islanders (2)       43% (8)
 4 (tie) New Jersey Devils (1)        43% (2)
 6       New York Rangers (1)         34% (12)
 7       Pittsburgh Penguins (3)      32% (13)
 8       Buffalo Sabres (1)           22%

West Division

 1       Vegas Golden Knights (2)     84% (9)
 2       Colorado Avalanche            82% (5)
 3       St. Louis Blues (2)          70% (9)
 4       Arizona Coyotes (2)          45% (11)
 5       Minnesota Wild (1)           43% (7)
 6       Anaheim Ducks (1)            30% (7)
 7       San Jose Sharks               27% (4)
 8       Los Angeles Kings (3)        19% (19)

North Division

 1       Toronto Maple Leafs           93% (7)
 2       Montreal Canadiens            85% (8)
 3       Winnipeg Jets                 78% (13)
 4       Calgary Flames                59%
 5       Edmonton Oilers (1)          49% (1)
 6       Vancouver Canucks (1)        29% (26)
 7       Ottawa Senators               7% (2)

Winning the President’s Trophy

 1 (tie) Boston Bruins (3)            16% (8)
 1 (tie) Tampa Bay Lightning           16% (6)
 3       Toronto Maple Leafs (1)      13% (4)
 4       Vegas Golden Knights (3)     10% (3)
 5       Colorado Avalanche (4)       7% (1)
 6 (tie) Carolina Hurricanes (3)      6%
 6 (tie) Montreal Canadiens (5)       6% (1)
 6 (tie) Philadelphia Flyers (2)      6% (2)
 9       Florida Panthers (2)         4% (3)
10 (tie) Dallas Stars (1)             3% (2)
10 (tie) St. Louis Blues (6)          3% (5)
10 (tie) Winnipeg Jets (3)            3% (1)
13       Washington Capitals (11)     2% (7)
14 (tie) Arizona Coyotes (10)         1% (1)
14 (tie) Calgary Flames (1)           1% (1)
14 (tie) Chicago Blackhawks (10)      1% (1)
14 (tie) Minnesota Wild (2)           1%
14 (tie) New York Islanders (2)       1%
14 (tie) New Jersey Devils (2)        1%

Everyone else has less than a 1% chance of winning the President’s Trophy.

Winning the Stanley Cup

 1 (tie) Boston Bruins                 9% (2)
 1 (tie) Tampa Bay Lightning           9% (2)
 3 (tie) Colorado Avalanche (2)       7%
 3 (tie) Toronto Maple Leafs (1)      7% (1)
 3 (tie) Vegas Golden Knights (5)     7% (2)
 6       Philadelphia Flyers (2)      6%
 7       St. Louis Blues (3)          5% (1)
 8 (tie) Carolina Hurricanes (1)      4%
 8 (tie) Dallas Stars (1)             4%
 8 (tie) Montreal Canadiens (1)       4%
 8 (tie) Winnipeg Jets (5)            4% (1)
12 (tie) Florida Panthers (3)         3% (1)
12 (tie) Washington Capitals (8)      3% (3)
14 (tie) Arizona Coyotes (3)          2%
14 (tie) Calgary Flames (1)           2% (1)
14 (tie) Chicago Blackhawks (11)      2% (1)
14 (tie) Columbus Blue Jackets (1)    2% (1)
14 (tie) Edmonton Oilers (3)          2%
14 (tie) Minnesota Wild (3)           2%
14 (tie) New York Islanders (3)       2%
14 (tie) New York Rangers (11)        2% (1)
14 (tie) New Jersey Devils (3)        2%
23 (tie) Anaheim Ducks (2)            1%
23 (tie) Buffalo Sabres (2)           1%
23 (tie) Los Angeles Kings (6)        1% (1)
23 (tie) Nashville Predators (6)      1% (1)
23 (tie) Pittsburgh Penguins (6)      1% (1)
23 (tie) San Jose Sharks (2)          1%
23 (tie) Vancouver Canucks (10)       1% (2)
30 (tie) Detroit Red Wings             <1%
30 (tie) Ottawa Senators               <1%

 

McDonald NHL Power Ratings – January 31, 2021

I’ve been calculating the “McDonald Power Ratings” in both the CFL and NHL for the last three years, mostly just for myself and my son, but last year, I started posting the NHL ones to my blog.  Unfortunately, the season shut down early, so I stopped doing them, and after the long COVID lay-off, I didn’t think they would be very accurate for last year’s playoffs.  But, I’ve started them again this year, and here’s the first posting for the year!  I’ll be posting the new ratings every Monday.

As more games are being played, the calibration of our internal models is beginning to settle down, so we’re starting to see less big jumps in ratings.  Boston, Tampa Bay, and Philadelphia continue to be the top three teams, although Colorado (3-0-1 this week) and St. Louis (3-0-0) both made big moves to round out the top five.

Other big movers this week included Washington (3-0-0, +11 rating points) and Toronto (2-0-1, +16 rating points), although the biggest mover was Vancouver (4-0-0, +27 rating points).

We’re currently predicting that Boston, Colorado, and Tampa Bay have the best chance of winning the Stanley Cup (7% chance for each), and Tampa Bay has the best chance of winning the President’s Trophy (10%).

At the bottom end of the scale, Ottawa (ranked 2nd last) and Detroit (ranked last) have less than a 1% chance of winning the Stanley Cup.  Ottawa had the biggest downward move, going 0-4-0 in the last week and dropping a whopping 23 rating points.

In the following rankings, the change indicated is the amount of change from the previous week.

The Top 5

1 (tie). Boston Bruins (1550, 5)

Record: 5-1-2, 3rd in East Division

Chances of: 

  • Making the playoffs: 77% (6)
  • Winning the President’s Trophy: 8% (1)
  • Winning the Stanley Cup: 7% (▲1)

Last week: 2-0-1

  • January 26: Won in OT 3-2 vs. Pittsburgh Penguins (18th, 1495)
  • January 28: Won 4-1 vs. Pittsburgh Penguins (18th, 1495)
  • January 30: Lost in OT 4-3 @ Washington Capitals (6th, 1540)

Next week:

  • February 1: @ Washington Capitals (6th, 1540)
  • February 3: @ Philadelphia Flyers (3rd, 1546)
  • February 5: @ Philadelphia Flyers (3rd, 1546)
  • February 6: vs. Buffalo Sabres (28th, 1461)

1 (tie). Tampa Bay Lightning 1 (1550, 6)

Record: 4-1-1, 5th in Central Division

Chances of: 

  • Making the playoffs: 78% (2)
  • Winning the President’s Trophy: 10%
  • Winning the Stanley Cup: 7%

Last week: 1-0-1

  • January 28: Lost in OT 1-0 @ Carolina Hurricanes (9th, 1517)
  • January 30: Won 4-3 vs. Nashville Predators (22th, 1487)

Next week:

  • February 1: vs. Nashville Predators (22th, 1487)
  • February 3: vs. Detroit Red Wings (31th, 1402)
  • February 5: vs. Detroit Red Wings (31th, 1402)

3 (tie). Colorado Avalanche 4 (1546, 18)

Record: 6-3-1, 2nd in West Division

Chances of: 

  • Making the playoffs: 77% (17)
  • Winning the President’s Trophy: 6% (3)
  • Winning the Stanley Cup: 7% (▲2)

Last week: 3-0-1

  • January 26: Won 7-3 vs. San Jose Sharks (28th, 1461)
  • January 28: Won 3-0 vs. San Jose Sharks (28th, 1461)
  • January 30: Won 5-1 @ Minnesota Wild (18th, 1495)
  • January 31: Lost in OT 4-3 @ Minnesota Wild (18th, 1495)

Next week:

  • February 2: vs. Minnesota Wild (18th, 1495)
  • February 4: vs. Minnesota Wild (18th, 1495)
  • February 6: @ St. Louis Blues (5th, 1544)
  • February 7: @ St. Louis Blues (5th, 1544)

3 (tie). Philadelphia Flyers (1546, 11)

Record: 7-2-1, 2nd in East Division

Chances of: 

  • Making the playoffs: 79% (17)
  • Winning the President’s Trophy: 8% (4)
  • Winning the Stanley Cup: 6% (▲1)

Last week: 4-0-0

  • January 26: Won 5-3 @ New Jersey Devils (16th, 1497)
  • January 28: Won 3-1 @ New Jersey Devils (16th, 1497)
  • January 30: Won in OT 3-2 vs. New York Islanders (16th, 1497)
  • January 31: Won in OT 4-3 vs. New York Islanders (16th, 1497)

Next week:

  • February 3: vs. Boston Bruins (1st, 1550)
  • February 5: vs. Boston Bruins (1st, 1550)
  • February 7: @ Washington Capitals (6th, 1540)

5. St. Louis Blues (1544, 15)

Record: 6-2-1, 1st in West Division

Chances of: 

  • Making the playoffs: 79% (16)
  • Winning the President’s Trophy: 8% (4)
  • Winning the Stanley Cup: 6% (▲1)

Last week: 3-0-0

  • January 26: Won in SO 5-4 @ Vegas Golden Knights (8th, 1533)
  • January 28: Game @ Vegas Golden Knights (8th, 1533) postponed
  • January 30: Won 6-1 @ Anaheim Ducks (27th, 1467)
  • January 31: Won 4-1 @ Anaheim Ducks (27th, 1467)

Next week:

  • February 2: vs. Arizona Coyotes (23th, 1486)
  • February 4: vs. Arizona Coyotes (23th, 1486)
  • February 6: vs. Colorado Avalanche (3rd, 1546)
  • February 7: vs. Colorado Avalanche (3rd, 1546)

Overall Ratings

 1 (tie) Boston Bruins                 1550 (5)
 1 (tie) Tampa Bay Lightning (1)      1550 (6)
 3 (tie) Colorado Avalanche (4)       1546 (18)
 3 (tie) Philadelphia Flyers           1546 (11)
 5       St. Louis Blues               1544 (15)
 6       Washington Capitals (1)      1540 (11)
 7       Toronto Maple Leafs (2)      1534 (16)
 8       Vegas Golden Knights (4)     1533 (1)
 9       Carolina Hurricanes (2)      1517 (6)
10       Dallas Stars (2)             1515 (4)
11       Florida Panthers (2)         1514 (7)
12       Columbus Blue Jackets (2)    1510 (2)
13       Montreal Canadiens (1)       1506 (3)
14       Calgary Flames (1)           1502 (5)
15       Winnipeg Jets (4)            1501 (2)
16 (tie) New York Islanders            1497 (8)
16 (tie) New Jersey Devils (1)        1497 (7)
18 (tie) Minnesota Wild (3)           1495 (11)
18 (tie) Pittsburgh Penguins (2)      1495 (3)
20       Edmonton Oilers (3)          1494 (10)
21       Vancouver Canucks (7)        1493 (27)
22       Nashville Predators (1)      1487 (8)
23       Arizona Coyotes (1)          1486 (2)
24       Los Angeles Kings             1483 (3)
25 (tie) Chicago Blackhawks (1)       1479 (2)
25 (tie) New York Rangers (2)         1479 (7)
27       Anaheim Ducks (2)            1467 (12)
28 (tie) Buffalo Sabres (1)           1461 (2)
28 (tie) San Jose Sharks (1)          1461 (10)
30       Ottawa Senators               1425 (23)
31       Detroit Red Wings             1402 (7)

Chances of Winning Division

Central Division

 1       Tampa Bay Lightning           29% (1)
 2       Florida Panthers (1)         21% (5)
 3       Carolina Hurricanes (1)      19% (5)
 4       Dallas Stars (2)             15% (5)
 5       Columbus Blue Jackets         8% (2)
 6       Nashville Predators           5% (2)
 7       Chicago Blackhawks            3% (1)
 8       Detroit Red Wings             <1% (1)

East Division

 1       Washington Capitals (1)      27% (7)
 2 (tie) Boston Bruins (1)            26% (2)
 2 (tie) Philadelphia Flyers (1)      26% (9)
 4       Pittsburgh Penguins (2)      7% (3)
 5       New Jersey Devils (1)        6% (6)
 6       New York Islanders (1)       4% (7)
 7 (tie) Buffalo Sabres (1)           2% (1)
 7 (tie) New York Rangers              2% (2)

West Division

 1       St. Louis Blues (1)          28% (10)
 2       Vegas Golden Knights (1)     26% (4)
 3       Colorado Avalanche            25% (10)
 4       Minnesota Wild (1)           8% (7)
 5       Los Angeles Kings             5% (1)
 6       Arizona Coyotes (1)          4% (1)
 7 (tie) Anaheim Ducks (2)            2% (4)
 7 (tie) San Jose Sharks               2% (3)

North Division

 1       Toronto Maple Leafs (1)      36% (12)
 2       Montreal Canadiens (1)       23% (4)
 3       Winnipeg Jets                 14% (3)
 4       Calgary Flames (1)           11% (6)
 5       Vancouver Canucks (1)        9% (6)
 6       Edmonton Oilers (1)          6% (4)
 7       Ottawa Senators (1)          <1% (3)

Making the Playoffs

Central Division

 1       Tampa Bay Lightning           78% (2)
 2       Florida Panthers (1)         70% (10)
 3       Carolina Hurricanes (1)      69% (10)
 4       Dallas Stars (2)             63% (3)
 5       Columbus Blue Jackets         50% (4)
 6       Nashville Predators           37% (6)
 7       Chicago Blackhawks            29% (5)
 8       Detroit Red Wings             4% (5)

East Division

 1       Philadelphia Flyers (2)      79% (17)
 2       Washington Capitals           78% (13)
 3       Boston Bruins (2)            77% (6)
 4       Pittsburgh Penguins (2)      45% (3)
 5       New Jersey Devils (1)        41% (12)
 6       New York Islanders (1)       35% (14)
 7 (tie) Buffalo Sabres (1)           22% (1)
 7 (tie) New York Rangers              22% (6)

West Division

 1       St. Louis Blues (1)          79% (16)
 2       Colorado Avalanche (1)       77% (17)
 3       Vegas Golden Knights (2)     75% (1)
 4       Minnesota Wild                50% (7)
 5       Los Angeles Kings             38% (1)
 6       Arizona Coyotes               34% (2)
 7 (tie) Anaheim Ducks (1)            23% (13)
 7 (tie) San Jose Sharks (1)          23% (11)

North Division

 1       Toronto Maple Leafs (1)      86% (10)
 2       Montreal Canadiens (1)       77% (1)
 3       Winnipeg Jets                 65% (2)
 4       Calgary Flames                59% (7)
 5       Vancouver Canucks (1)        55% (25)
 6       Edmonton Oilers (1)          48% (7)
 7       Ottawa Senators               9% (18)

Winning the President’s Trophy

 1       Tampa Bay Lightning           10%
 2 (tie) Toronto Maple Leafs (3)      9% (3)
 2 (tie) Washington Capitals (5)      9% (4)
 4 (tie) Boston Bruins (1)            8% (1)
 4 (tie) Philadelphia Flyers (5)      8% (4)
 4 (tie) St. Louis Blues (5)          8% (4)
 7 (tie) Florida Panthers              7% (2)
 7 (tie) Vegas Golden Knights (5)     7% (2)
 9 (tie) Carolina Hurricanes           6% (2)
 9 (tie) Colorado Avalanche (5)       6% (3)
11 (tie) Dallas Stars (6)             5% (1)
11 (tie) Montreal Canadiens (8)       5% (2)
13 (tie) Calgary Flames (4)           2% (2)
13 (tie) Columbus Blue Jackets (1)    2% (1)
13 (tie) Winnipeg Jets (4)            2% (2)
16 (tie) Edmonton Oilers (4)          1%
16 (tie) Los Angeles Kings (4)        1%
16 (tie) Minnesota Wild (2)           1% (2)
16 (tie) New York Islanders (2)       1% (1)
16 (tie) Nashville Predators (4)      1%
16 (tie) New Jersey Devils (2)        1% (2)
16 (tie) Pittsburgh Penguins (2)      1% (1)
16 (tie) Vancouver Canucks (12)       1% (1)

Everyone else has less than a 1% chance of winning the President’s Trophy.

Winning the Stanley Cup

 1 (tie) Boston Bruins (1)            7% (1)
 1 (tie) Colorado Avalanche (3)       7% (2)
 1 (tie) Tampa Bay Lightning           7%
 4 (tie) Philadelphia Flyers           6% (1)
 4 (tie) St. Louis Blues               6% (1)
 4 (tie) Toronto Maple Leafs           6% (1)
 4 (tie) Washington Capitals           6% (1)
 8       Vegas Golden Knights (6)     5% (1)
 9 (tie) Carolina Hurricanes           4%
 9 (tie) Dallas Stars                  4%
 9 (tie) Florida Panthers              4%
 9 (tie) Montreal Canadiens            4%
13 (tie) Calgary Flames (4)           3% (1)
13 (tie) Columbus Blue Jackets (2)    3%
13 (tie) Vancouver Canucks (14)       3% (2)
13 (tie) Winnipeg Jets (4)            3% (1)
17 (tie) Arizona Coyotes (4)          2%
17 (tie) Edmonton Oilers (2)          2% (1)
17 (tie) Los Angeles Kings (4)        2%
17 (tie) Minnesota Wild (2)           2% (1)
17 (tie) New York Islanders (2)       2% (1)
17 (tie) Nashville Predators (4)      2%
17 (tie) New Jersey Devils (2)        2% (1)
17 (tie) Pittsburgh Penguins (2)      2% (1)
25 (tie) Anaheim Ducks (4)            1% (1)
25 (tie) Buffalo Sabres (2)           1%
25 (tie) Chicago Blackhawks (4)       1% (1)
25 (tie) New York Rangers (4)         1% (1)
25 (tie) San Jose Sharks (2)          1%
30 (tie) Detroit Red Wings (1)        <1%
30 (tie) Ottawa Senators (3)          <1% (1)

2021 NHL schedule and results in Excel .xlsx and csv formats

Hockey playerThe post you’re currently reading is about the 2021 NHL schedule.  If you’re looking for the 2023/24 NHL schedule, you can find it in this post. If you want the 2022/23 schedule, it’s in this post.  And the 2021/22 schedule is here.

Here’s a copy of the 2021 NHL schedule and the results of each of the games played so far in Excel .xlsx format, and here’s another copy in CSV format.  They are up-to-date up to last night, and I’ll try to update them each morning through the regular season.

The Excel file consists of 2 worksheets: one contains the original NHL schedule as described in this post; the other, named As-Played Schedule, contains the same contents, with the addition of the scores for each team and whether the game hasn’t been played yet, was won in regulation time, overtime, or in a shootout.  Here’s a quick summary of the columns:

  • Date: the date of the game
  • Start Time (Sask): the game’s start time in Saskatchewan (where I live!)
  • Start Time (ET): the game’s start time in Eastern time (which is the time the NHL website shows)
  • Visitor: the name of the visiting team
  • Score: the visiting team’s score if the game has been played, otherwise blank
  • Home: the name of the home team
  • Score: the home team’s score if the game has been played, otherwise blank
  • Status: one of the following:
    • Scheduled: if the game hasn’t been played yet
    • Regulation: if the game ended in regulation time
    • OT: if the game ended in overtime
    • SO: if the game ended in a shootout

For example, here’s the first couple lines of the worksheet:

In this example, the game was played on January 13, 2021 at 4:30 PM in Saskatchewan and 5:30 PM Eastern time, the home team Philadelphia beat the visiting team Pittsburgh 6-3 in regulation time

Just a brief explanation why I’ve got two time fields in here.  Saskatchewan doesn’t observe Daylight Savings time, so for the first part of the schedule, we have a one-hour time difference from Eastern time, but once the rest of the country leaps forward, we have a two-hour time difference.  Of course, I’m more interested in the time in Saskatchewan, but to make it easier for other people to use, I’ve also included Eastern time.

The CSV file contains only the As-Played worksheet.  It has the same fields as described for the Excel file.  You can easily import this file into Excel or whatever spreadsheet of your choice!

The 2021 NHL Schedule in Excel .xlsx format

Hockey playerNote: If you’re looking for the 2021/22 NHL schedule in Excel or CSV format, you can find it in this post.

Here’s a copy of the 2020/21 NHL schedule in Excel .xlsx format.

In a previous post, I posted a copy of the original 2020/21 NHL schedule in CSV format.  I’ve seen quite a few people looking for a schedule in Excel .xlsx format.  Although you can quite easily import a CSV file into Excel, I thought I might import it myself, apply a little bit of formatting to the file, and make it available, too.  You can get it here.

Update: you might also be interested in a spreadsheet that also contains the results.  You can read about it in this post.

Be aware that this is the schedule as of January 12, 2021.  In my original post, I said that I wouldn’t be surprised if the schedule changes, either due to weather-related game cancellations, or, more likely, changes due to COVID.  Well, that has definitely happened, even last night when the St. Louis Blues and Vegas Golden Knights game was postponed due to COVID.  That is NOT reflected in this schedule; this is the original schedule before any changes were made.

This spreadsheet contains 5 fields.  The first field is the date of the game, the second field is the game’s start time in Saskatchewan (where I live!), the third field is the game’s start time in Eastern Time (which is the time the NHL website shows), the fourth field is the visiting team, and the fifth field is the home team.

Here’s a screenshot of the first few lines of the file:

First two lines of schedule spreadsheet

The first line, obviously, is the header line, giving a brief description of each of the fields.  The second line, and all subsequent lines, list the games in the schedule, one for each game.  For the first game shown here, we can see:

  • the date of the first game is January 13, 2021
  • the game starts at 4:30 p.m. Saskatchewan time
  • the game starts at 5:30 p.m. Eastern time
  • the visiting team is the Pittsburgh Penguins
  • the home team is the Philadelphia Flyers

Just a brief explanation why I’ve got two time fields in here.  Saskatchewan doesn’t observe Daylight Savings time, so for the first part of the schedule, we have a one-hour time difference from Eastern time, but once the rest of the country leaps forward, we have a two-hour time difference.  Of course, I’m more interested in the time in Saskatchewan, but to make it easier for other people to use, I’ve also included Eastern time.

If you can make use of this file, have fun!

 

Here’s a machine-readable copy of the 2021 NHL schedule

Hockey playerNote: If you’re looking for the 2021/22 NHL schedule in Excel or CSV format, you can find it in this post.

Here’s a CSV file of the NHL schedule, ready to be imported into Excel or your favourite spreadsheet.

Update: I’ve also made an Excel xlsx file available.  See the post here.

Another update: you might also be interested in a spreadsheet that contains the game results.  You can read about it in this post.

I’m quite excited, because the new NHL season is about to start! I was looking for a copy of this season’s schedule in a machine-readable format, but I wasn’t able to find one.  So, I created one.  You can get it here.

Be aware that this is the schedule as of January 12, 2021.  I wouldn’t be surprised if the schedule changes, either due to weather-related game cancellations, or, more likely, changes due to COVID.

This is a CSV (comma-separated value) file, with 5 fields.  The first field is the date of the game, the second field is the game’s start time in Saskatchewan (where I live!), the third field is the game’s start time in Eastern Time (which is the time the NHL website shows), the fourth field is the visiting team, and the fifth field is the home team.  You can easily import this file into Excel, Google Sheets, or whatever spreadsheet you like to use.

Here’s the first couple lines of the file:

Date,Start Time (Sask),Start Time (ET),Visitor,Home
2021-01-13,4:30 PM,5:30 PM,Pittsburgh Penguins,Philadelphia Flyers

The first line, obviously, is the header line, giving a brief description of each of the fields.  The second line, and all subsequent lines, list the games in the schedule, one for each game.  For the example line shown here, we can see:

  • the date of the first game is January 13, 2021
  • the game starts at 4:30 p.m. Saskatchewan time
  • the game starts at 5:30 p.m. Eastern time
  • the visiting team is the Pittsburgh Penguins
  • the home team is the Philadelphia Flyers

Just a brief explanation why I’ve got two time fields in here.  Saskatchewan doesn’t observe Daylight Savings time, so for the first part of the schedule, we have a one-hour time difference from Eastern time, but once the rest of the country leaps forward, we have a two-hour time difference.  Of course, I’m more interested in the time in Saskatchewan, but to make it easier for other people to use, I’ve also included Eastern time.

If you can make use of this file, have fun!

How to install wxPython in a Python virtual environment on Debian Buster

wxPython logoLately, I’ve been brushing up on my Python skills, and decided to use wxPython for some GUI programming.  But, I had some trouble installing wxPython in a Python virtual environment on Debian, so once I figured it out, I’ve recorded what I had to do in case anyone else needs to do the same thing.

Note that if you’re NOT using a virtual environment, it’s pretty easy: just install the “python3-wxgtk4.0” package.  Of course, if you’re using Python 2, you’ll need something else, but because Python 2 has reached end-of-life, I don’t know why you’d want to use that!  Anyways, just as a refresher, to install a Debian package, you’ll need to run the following from the command line as root:

apt-get install python3-wxgtk4.0

You may, of course, need to run it with sudo to run as root:

sudo apt-get install python3-wxgtk4.0

In this post, rather than saying whether to run something as root or as a regular user, I’m just going to prepend the root commands with “sudo”; if you get root access another way, do that instead.

OK, but as I said, I want to install wxPython in a Python virtual environment.  The problem comes because Python needs to compile wxPython, so you need a number of development packages installed.  You actually need hundreds of packages (!), but I’ve narrowed it down to a short list, and the other packages will be installed as dependencies of these ones.

Note that I am currently running Debian Buster.  I’ve tried this out with a basic non-GUI install of Buster, as well as with the XFCE desktop installed (which I set up via “sudo tasksel install xfce-desktop”).

First thing you need to do if you’re going to use Python virtual environments on Debian is to install the Python virtual environment package:

sudo apt-get install python3-venv

Now, you can create your Python virtual environment:

python3 -m venv example-env

This will create your Python virtual environment in a directory called example-env.

Now, install all of required Debian development packages:

sudo apt-get install build-essential python3-dev \
  libwebkit2gtk-4.0-dev libtiff-dev libnotify-dev \
  freeglut3-dev libsdl1.2-dev libgstreamer-plugins-base1.0-dev

This will cause hundreds of packages to be installed, so don’t be surprised when that happens!

Once you’ve got those installed, you’re almost all set.  Activate your Python virtual environment:

source example-env/bin/activate

Using Python’s “pip” program, install the “wheel” Python package into the virtual environment:

pip install wheel

And now, finally, you can install wxPython:

pip install wxPython

Be aware that this is going to result in the wxPython package being compiled, which can take a LONG time.  Don’t be surprised if it takes an hour or more.  But, once it’s successfully installed, you can use wxPython in your virtual environment!  I tested it out by running the helloworld2.py program found on the wxPython Overview page.

Have fun!

McDonald NHL Power Ratings – March 8, 2020

Philadelphia has continued their winning ways, increasing their rating by 18 points.  I’ve now got them at a 10% chance of winning the Stanley Cup.  They’ve got two tough games coming up though: #1 Boston on Tuesday, and #2 Tampa Bay on Thursday.

Boston is still the favourite, with a 15% chance of winning the Stanley Cup, down 1% from last week.

The top 5

1. Boston Bruins (1595, 2)

Record: 43-14-12, 1st in Atlantic Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 79% (11)
  • Winning the Stanley Cup: 15% (1)

Last week: 2-1-0

  • March 3: Won 2-1 @ Tampa Bay Lightning (2nd, 1584)
  • March 5: Won in OT 2-1 @ Florida Panthers (17th, 1506)
  • March 7: Lost 5-3 vs. Tampa Bay Lightning (2nd, 1584)

Next week:

  • March 10: @ Philadelphia Flyers (4th, 1569)
  • March 13: @ Buffalo Sabres (29th, 1435)
  • March 14: vs. Toronto Maple Leafs (13th, 1511)

2. Tampa Bay Lightning (1584, 1)

Record: 43-20-6, 2nd in Atlantic Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 8% (5)
  • Winning the Stanley Cup: 12% (1)

Last week: 2-1-1

  • March 3: Lost 2-1 vs. Boston Bruins (1st, 1595)
  • March 5: Won 4-0 vs. Montreal Canadiens (28th, 1446)
  • March 7: Won 5-3 @ Boston Bruins (1st, 1595)
  • March 8: Lost in SO 5-4 @ Detroit Red Wings (31st, 1348)

Next week:

  • March 10: @ Toronto Maple Leafs (13th, 1511)
  • March 12: vs. Philadelphia Flyers (4th, 1569)
  • March 14: vs. Detroit Red Wings (31st, 1348)
  • March 15: vs. New Jersey Devils (20th, 1492)

3. Colorado Avalanche 1 (1580, 3)

Record: 41-19-8, 2nd in Central Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 6% (4)
  • Winning the Stanley Cup: 13%

Last week: 2-1-1

  • March 2: Won 2-1 @ Detroit Red Wings (31st, 1348)
  • March 4: Lost in OT 4-3 vs. Anaheim Ducks (26th, 1447)
  • March 6: Lost 6-3 @ Vancouver Canucks (23rd, 1485)
  • March 8: Won 4-3 @ San Jose Sharks (25th, 1453)

Next week:

  • March 9: @ Los Angeles Kings (26th, 1447)
  • March 11: vs. New York Rangers (19th, 1504)
  • March 13: vs. Vancouver Canucks (23rd, 1485)
  • March 15: vs. Vegas Golden Knights (7th, 1537)

4. Philadelphia Flyers 1 (1569, 18)

Record: 41-20-7, 2nd in Metropolitan Division

Chances of:

  • Making the playoffs: >99% (3)
  • Winning the President’s Trophy: 2% (2)
  • Winning the Stanley Cup: 10% (3)

Last week: 3-0-0

  • March 4: Won 5-2 @ Washington Capitals (6th, 1539)
  • March 5: Won 4-1 vs. Carolina Hurricanes (14th, 1509)
  • March 7: Won 3-1 vs. Buffalo Sabres (29th, 1435)

Next week:

  • March 10: vs. Boston Bruins (1st, 1595)
  • March 12: @ Tampa Bay Lightning (2nd, 1584)
  • March 14: vs. Minnesota Wild (10th, 1516)
  • March 15: vs. Edmonton Oilers (8th, 1527)

5. St. Louis Blues 1 (1558, 6)

Record: 41-18-10, 1st in Central Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 4% (1)
  • Winning the Stanley Cup: 9% (1)

Last week: 2-1-0

  • March 3: Won 3-1 @ New York Rangers (19th, 1504)
  • March 6: Lost 4-2 @ New Jersey Devils (20th, 1492)
  • March 8: Won 2-0 @ Chicago Black Hawks (24th, 1459)

Next week:

  • March 9: vs. Florida Panthers (17th, 1506)
  • March 11: @ Anaheim Ducks (26th, 1447)
  • March 13: vs. San Jose Sharks (25th, 1453)
  • March 15: vs. Ottawa Senators (30th, 1424)

Overall Ratings

 1       Boston Bruins                 1595 (2)
 2       Tampa Bay Lightning           1584 (1)
 3       Colorado Avalanche (1)       1580 (3)
 4       Philadelphia Flyers (1)      1569 (18)
 5       St. Louis Blues (1)          1558 (6)
 6       Washington Capitals           1539
 7       Vegas Golden Knights          1537 (7)
 8       Edmonton Oilers (4)          1527 (8)
 9       Columbus Blue Jackets (2)    1522 (2)
10       Minnesota Wild (3)           1516 (3)
11 (tie) Dallas Stars (4)             1513 (17)
11 (tie) Winnipeg Jets (8)            1513 (13)
13       Toronto Maple Leafs (4)      1511 (17)
14 (tie) Carolina Hurricanes (4)      1509 (4)
14 (tie) Nashville Predators (3)      1509 (2)
16       Pittsburgh Penguins (3)      1508 (5)
17       Florida Panthers (3)         1506 (7)
18       Calgary Flames (3)           1505 (3)
19       New York Rangers (9)         1504 (17)
20       New Jersey Devils (3)        1492 (12)
21 (tie) Arizona Coyotes (1)          1489 (3)
21 (tie) New York Islanders (6)       1489 (19)
23       Vancouver Canucks (2)        1485 (8)
24       Chicago Blackhawks            1459 (3)
25       San Jose Sharks               1453 (7)
26 (tie) Anaheim Ducks (2)            1447 (7)
26 (tie) Los Angeles Kings (3)        1447 (10)
28       Montreal Canadiens (1)       1446
29       Buffalo Sabres (3)           1435 (17)
30       Ottawa Senators               1424 (5)
31       Detroit Red Wings             1348 (10)

Chances of Winning Division

Metropolitan Division

 1       Washington Capitals           50% (12)
 2       Philadelphia Flyers           45% (23)
 3       Pittsburgh Penguins           4% (7)
 4 (tie) Carolina Hurricanes (1)      <1% (1)
 4 (tie) Columbus Blue Jackets (2)    <1%
 4 (tie) New York Islanders            <1% (3)
 4 (tie) New York Rangers (2)         <1%
 4 (tie) New Jersey Devils (2)        <1%

Atlantic Division

 1       Boston Bruins                 89% (8)
 2       Tampa Bay Lightning           11% (8)
 3 (tie) Buffalo Sabres                <1%
 3 (tie) Detroit Red Wings             <1%
 3 (tie) Florida Panthers              <1%
 3 (tie) Montreal Canadiens            <1%
 3 (tie) Ottawa Senators               <1%
 3 (tie) Toronto Maple Leafs           <1%

Central Division

 1       Colorado Avalanche            53% (6)
 2       St. Louis Blues               46% (9)
 3 (tie) Chicago Blackhawks (1)       <1%
 3 (tie) Dallas Stars                  <1% (4)
 3 (tie) Minnesota Wild (1)           <1%
 3 (tie) Nashville Predators (1)      <1%
 3 (tie) Winnipeg Jets (1)            <1%

Pacific Division

 1       Vegas Golden Knights          48%
 2       Edmonton Oilers               43% (11)
 3 (tie) Calgary Flames (1)           4% (4)
 3 (tie) Vancouver Canucks             4% (8)
 5 (tie) Anaheim Ducks (1)            <1%
 5 (tie) Arizona Coyotes               <1% (1)
 5 (tie) Los Angeles Kings (1)        <1%
 5 (tie) San Jose Sharks (1)          <1%

Making the Playoffs

Eastern Conference

 1 (tie) Boston Bruins                 >99%
 1 (tie) Philadelphia Flyers (3)      >99% (3)
 1 (tie) Tampa Bay Lightning           >99%
 1 (tie) Washington Capitals           >99%
 5       Pittsburgh Penguins           91% (2)
 6       Toronto Maple Leafs           71% (17)
 7       Carolina Hurricanes (1)      69% (20)
 8       New York Islanders (1)       59% (20)
 9       Columbus Blue Jackets         47% (6)
10       Florida Panthers (1)         41% (19)
11       New York Rangers (1)         21% (14)
12 (tie) Buffalo Sabres                <1% (1)
12 (tie) Detroit Red Wings (2)        <1%
12 (tie) Montreal Canadiens            <1% (1)
12 (tie) New Jersey Devils (2)        <1%
12 (tie) Ottawa Senators (2)          <1%

Western Conference

 1 (tie) Colorado Avalanche            >99%
 1 (tie) St. Louis Blues               >99%
 3 (tie) Dallas Stars                  97% (2)
 3 (tie) Edmonton Oilers (2)          97% (7)
 3 (tie) Vegas Golden Knights (1)     97% (2)
 6       Calgary Flames (1)           70% (3)
 7       Minnesota Wild (2)           59% (10)
 8       Vancouver Canucks (2)        56% (17)
 9       Nashville Predators (1)      53% (7)
10       Winnipeg Jets (1)            42% (13)
11       Arizona Coyotes (1)          25% (5)
12       Chicago Blackhawks            2% (5)
13 (tie) Anaheim Ducks                 <1%
13 (tie) Los Angeles Kings             <1%
13 (tie) San Jose Sharks               <1%

Winning the President’s Trophy

 1       Boston Bruins                 79% (11)
 2       Tampa Bay Lightning           8% (5)
 3       Colorado Avalanche            6% (4)
 4       St. Louis Blues               4% (1)
 5       Philadelphia Flyers (1)      2% (2)
 6       Washington Capitals (1)      1% (2)

Everyone else has less than a 1% chance of winning the President’s Trophy.

Winning the Stanley Cup

 1       Boston Bruins                 15% (1)
 2       Colorado Avalanche            13%
 3       Tampa Bay Lightning           12% (1)
 4       Philadelphia Flyers (1)      10% (3)
 5       St. Louis Blues (1)          9% (1)
 6       Vegas Golden Knights (1)     6% (1)
 7 (tie) Edmonton Oilers (1)          5% (1)
 7 (tie) Washington Capitals (1)      5% (1)
 9 (tie) Dallas Stars (1)             3% (1)
 9 (tie) Pittsburgh Penguins (1)      3%
11 (tie) Calgary Flames (1)           2% (1)
11 (tie) Carolina Hurricanes (2)      2%
11 (tie) Columbus Blue Jackets (2)    2%
11 (tie) Minnesota Wild (2)           2%
11 (tie) Nashville Predators (2)      2%
11 (tie) Toronto Maple Leafs (1)      2% (1)
11 (tie) Winnipeg Jets (9)            2% (1)
18 (tie) Arizona Coyotes (2)          1%
18 (tie) Florida Panthers (2)         1%
18 (tie) New York Islanders (5)       1% (1)
18 (tie) New York Rangers (5)         1% (1)
18 (tie) Vancouver Canucks (5)        1% (1)
23 (tie) Anaheim Ducks                 <1%
23 (tie) Buffalo Sabres                <1%
23 (tie) Chicago Blackhawks            <1%
23 (tie) Detroit Red Wings             <1%
23 (tie) Los Angeles Kings             <1%
23 (tie) Montreal Canadiens            <1%
23 (tie) New Jersey Devils             <1%
23 (tie) Ottawa Senators               <1%
23 (tie) San Jose Sharks               <1%

McDonald NHL Power Ratings – March 1, 2020

I’ve been working on a little project for the last couple of years to predict who’s going to win the Stanley Cup.  It’s based on Elo ratings, with my own little tweaks to optimize the predictions, and with those ratings, I simulate the entire season 100,000 times to see what the chances are of each team winning the Stanley Cup.  Anyways, I thought that I would post my current “McDonald NHL Power Ratings” on my blog.  There’s still some changes I want to make to these reports, but here’s what I’ve got right now!

Note that the changes in ratings and rankings are the changes relative to last week (February 23).  Also, note that the average team rating is 1500; teams with a higher rating are above average, and those below are below average.

The top 5

1. Boston Bruins 1 (1597, 3)

Record: 41-13-12, 1st in Atlantic Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 68% (11)
  • Winning the Stanley Cup: 16% (2)

Last week: 2-1-0

  • February 25: Lost 5-2 vs. Calgary Flames (15th, 1508)
  • February 27: Won 4-3 vs. Dallas Stars (7th, 1530)
  • February 29: Won 4-0 @ New York Islanders (15th, 1508)

Next week:

  • March 3: @ Tampa Bay Lightning (2nd, 1583)
  • March 5: @ Florida Panthers (20th, 1499)
  • March 7: vs. Tampa Bay Lightning (2nd, 1583)

2 (tie). Colorado Avalanche 1 (1583, 19)

Record: 39-18-7, 2nd in Central Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 10% (7)
  • Winning the Stanley Cup: 13% (3)

Last week: 3-0-0

  • February 26: Won 3-2 vs. Buffalo Sabres (26th, 1452)
  • February 28: Won 3-2 @ Carolina Hurricanes (18th, 1505)
  • February 29: Won 3-2 @ Nashville Predators (17th, 1507)

Next week:

  • March 2: @ Detroit Red Wings (31st, 1388)
  • March 4: vs. Anaheim Ducks (28th, 1440)
  • March 6: @ Vancouver Canucks (21st, 1493)
  • March 8: @ San Jose Sharks (25th, 1460)

2 (tie). Tampa Bay Lightning 1 (1583, 16)

Record: 41-19-5, 2nd in Atlantic Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 13% (19)
  • Winning the Stanley Cup: 11% (4)

Last week: 1-2-0

  • February 25: Lost 4-3 vs. Toronto Maple Leafs (9th, 1528)
  • February 27: Lost 5-2 vs. Chicago Blackhawks (24th, 1462)
  • February 29: Won 4-3 vs. Calgary Flames (15th, 1508)

Next week:

  • March 3: vs. Boston Bruins (1st, 1597)
  • March 5: vs. Montreal Canadiens (27th, 1446)
  • March 7: @ Boston Bruins (1st, 1597)
  • March 8: @ Detroit Red Wings (31st, 1338)

4. St. Louis Blues (1552, 2)

Record: 39-17-10, 1st in Central Division

Chances of:

  • Making the playoffs: >99%
  • Winning the President’s Trophy: 5% (3)
  • Winning the Stanley Cup: 8%

Last week: 3-0-0

  • February 25: Won 6-5 vs. Chicago Blackhawks (24th, 1462)
  • February 27: Won in OT 3-2 vs. New York Islanders (15th, 1508)
  • February 29: Won in SO 4-3 vs. Dallas Stars (7th, 1530)

Next week:

  • March 3: @ New York Rangers (10th, 1521)
  • March 6: @ New Jersey Devils (23rd, 1480)
  • March 8: @ Chicago Blackhawks (24th, 1462)

5. Philadelphia Flyers 3 (1551, 20)

Record: 38-20-7, 2nd in Metropolitan Division

Chances of:

  • Making the playoffs: 97% (17)
  • Winning the President’s Trophy: <1%
  • Winning the Stanley Cup: 7% (3)

Last week: 3-0-0

  • February 25: Won 4-2 vs. San Jose Sharks (25th, 1460)
  • February 28: Won 5-2 vs. New York Rangers (10th, 1521)
  • March 1: Won 5-3 @ New York Rangers (10th, 1521)

Next week:

  • March 4: @ Washington Capitals (6th, 1539)
  • March 5: vs. Carolina Hurricanes (18th, 1505)
  • March 7: vs. Buffalo Sabres (26th, 1452)

Overall Ratings

 1       Boston Bruins (1)            1597 (3)
 2 (tie) Colorado Avalanche (1)       1583 (19)
 2 (tie) Tampa Bay Lightning (1)      1583 (16)
 4       St. Louis Blues               1552 (2)
 5       Philadelphia Flyers (3)      1551 (20)
 6       Washington Capitals (1)      1539 (1)
 7 (tie) Dallas Stars (4)             1530 (3)
 7 (tie) Vegas Golden Knights (2)     1530
 9       Toronto Maple Leafs (9)      1528 (24)
10       New York Rangers              1521 (7)
11       Columbus Blue Jackets (4)    1520 (13)
12       Edmonton Oilers               1519 (1)
13 (tie) Minnesota Wild (6)           1513 (13)
13 (tie) Pittsburgh Penguins (7)      1513 (26)
15 (tie) Calgary Flames (6)           1508 (15)
15 (tie) New York Islanders (1)       1508 (6)
17       Nashville Predators (1)      1507 (3)
18       Carolina Hurricanes (6)      1505 (15)
19       Winnipeg Jets (1)            1500 (4)
20       Florida Panthers (4)         1499 (11)
21       Vancouver Canucks (7)        1493 (21)
22       Arizona Coyotes               1486 (2)
23       New Jersey Devils (1)        1480 (14)
24       Chicago Blackhawks (2)       1462 (8)
25       San Jose Sharks               1460 (3)
26       Buffalo Sabres (3)           1452 (16)
27       Montreal Canadiens            1446 (7)
28       Anaheim Ducks                 1440 (2)
29       Los Angeles Kings             1437 (20)
30       Ottawa Senators               1419 (4)
31       Detroit Red Wings             1338 (8)

Chances of Winning Division

Metropolitan Division

 1       Washington Capitals           62% (15)
 2       Philadelphia Flyers (1)      22% (16)
 3       Pittsburgh Penguins (1)      11% (25)
 4       New York Islanders (1)       3% (3)
 5       Carolina Hurricanes           1% (2)
 6 (tie) Columbus Blue Jackets         <1% (1)
 6 (tie) New York Rangers              <1% (1)
 6 (tie) New Jersey Devils (2)        <1%

Atlantic Division

 1       Boston Bruins                 81% (18)
 2       Tampa Bay Lightning           19% (18)
 3 (tie) Buffalo Sabres                <1%
 3 (tie) Detroit Red Wings             <1%
 3 (tie) Florida Panthers              <1%
 3 (tie) Montreal Canadiens            <1%
 3 (tie) Ottawa Senators               <1%
 3 (tie) Toronto Maple Leafs           <1%

Central Division

 1       Colorado Avalanche            59% (13)
 2       St. Louis Blues               37% (4)
 3       Dallas Stars                  4% (8)
 4 (tie) Chicago Blackhawks            <1%
 4 (tie) Minnesota Wild                <1%
 4 (tie) Nashville Predators           <1%
 4 (tie) Winnipeg Jets                 <1%

Pacific Division

 1       Vegas Golden Knights          48% (10)
 2       Edmonton Oilers               32% (2)
 3       Vancouver Canucks             12% (16)
 4       Calgary Flames                8% (5)
 5       Arizona Coyotes               1%
 6 (tie) Anaheim Ducks                 <1%
 6 (tie) Los Angeles Kings             <1%
 6 (tie) San Jose Sharks               <1%

Making the Playoffs

Eastern Conference

 1 (tie) Boston Bruins                 >99%
 1 (tie) Tampa Bay Lightning           >99%
 1 (tie) Washington Capitals (2)      >99% (2)
 4       Philadelphia Flyers (1)      97% (17)
 5       Pittsburgh Penguins (1)      89% (7)
 6       Toronto Maple Leafs (2)      88% (37)
 7       New York Islanders (1)       79%
 8       Carolina Hurricanes (1)      49% (15)
 9       Columbus Blue Jackets (1)    41% (2)
10       New York Rangers (1)         35% (3)
11       Florida Panthers (2)         22% (27)
12 (tie) Buffalo Sabres                1% (5)
12 (tie) Montreal Canadiens (1)       1% (1)
14 (tie) Detroit Red Wings             <1%
14 (tie) New Jersey Devils             <1%
14 (tie) Ottawa Senators               <1%

Western Conference

 1 (tie) Colorado Avalanche            >99%
 1 (tie) St. Louis Blues               >99%
 3       Dallas Stars                  99%
 4       Vegas Golden Knights          95% (1)
 5       Edmonton Oilers               90% (1)
 6       Vancouver Canucks             73% (16)
 7       Calgary Flames (1)           67% (16)
 8       Nashville Predators (1)      60% (3)
 9       Minnesota Wild (1)           49% (13)
10       Arizona Coyotes (1)          30% (7)
11       Winnipeg Jets                 29% (5)
12       Chicago Blackhawks            7% (2)
13 (tie) Anaheim Ducks                 <1%
13 (tie) Los Angeles Kings             <1%
13 (tie) San Jose Sharks               <1%

Winning the President’s Trophy

 1       Boston Bruins                 68% (11)
 2       Tampa Bay Lightning           13% (19)
 3       Colorado Avalanche            10% (7)
 4       St. Louis Blues (1)          5% (3)
 5       Washington Capitals (2)      3%

Everyone else has less than a 1% chance of winning the President’s Trophy.

Winning the Stanley Cup

 1       Boston Bruins (1)            16% (2)
 2       Colorado Avalanche (1)       13% (3)
 3       Tampa Bay Lightning (2)      11% (4)
 4       St. Louis Blues               8%
 5       Philadelphia Flyers (4)      7% (3)
 6       Washington Capitals (1)      6% (1)
 7       Vegas Golden Knights (2)     5%
 8 (tie) Dallas Stars (3)             4% (1)
 8 (tie) Edmonton Oilers (1)          4%
10 (tie) Calgary Flames (6)           3% (1)
10 (tie) Pittsburgh Penguins (5)      3% (2)
10 (tie) Toronto Maple Leafs (9)      3% (2)
13 (tie) Carolina Hurricanes (1)      2% (1)
13 (tie) Columbus Blue Jackets (1)    2% (1)
13 (tie) Minnesota Wild (6)           2% (1)
13 (tie) New York Islanders (1)       2% (1)
13 (tie) New York Rangers (3)         2%
13 (tie) Nashville Predators (1)      2% (1)
13 (tie) Vancouver Canucks (4)        2% (2)
20 (tie) Arizona Coyotes (1)          1%
20 (tie) Florida Panthers (4)         1% (1)
20 (tie) Winnipeg Jets (1)            1%
23 (tie) Anaheim Ducks                 <1%
23 (tie) Buffalo Sabres                <1%
23 (tie) Chicago Blackhawks            <1%
23 (tie) Detroit Red Wings             <1%
23 (tie) Los Angeles Kings             <1%
23 (tie) Montreal Canadiens            <1%
23 (tie) New Jersey Devils             <1%
23 (tie) Ottawa Senators               <1%
23 (tie) San Jose Sharks               <1%

 

Simple Date Processing in Java with LocalDate

Calendar icon
Image courtesy of https://www.stockio.com/free-icon/karlton-icon-set-calendar

I’m working on a project in Java, and I wanted to do some simple processing of dates.  I tried reading the Java tutorials and looking at questions and answers on Stack Overflow, but the solutions they offered were too complicated for what I was looking for, or were using classes that were old and not recommended to be used.  I finally figured out a nice easy way to handle the processing, so I thought I’d document it here.

What I was trying to do

The dates I have are stored in Strings, in the format “YYYY-MM-DD”; for example, June 30, 2019 is stored as “2019-06-30”.  This is a nice easy format to work with; I don’t need to concern myself with timezones or anything complicated, and it’s easy to sort and compare, because I can just do String comparisons with the compareTo() method.

Besides comparisons and sorting, I also want to do some other processing: getting the date the day before, the week before, and the week after.  This isn’t so easy to do; I would need to write a bunch of code that knows how many days there are in the month, and handle the case of moving to previous months or years, and deal with leap years, etc., etc., etc.  Yeah, I know it’s not that hard, but it would be easier to use some pre-existing, exhaustively tested code to do it!

Java’s LocalDate class is the solution

It turns out the best way to do this is to use Java’s LocalDate class, in the java.time package.  A LocalDate object contains a date without a timezone, using the standard Gregorian calendar that we all know and love in Canada (and most of the world).  If you really want to know more details about the calendar (you don’t need to to understand this blog post), you can read about the ISO 8601 calendar on Wikipedia.

Creating a LocalDate object

Creating a LocalDate object was really easy for me.  Because I’ve already got the date stored in my program in a String in the format YYYY-MM-DD, I can just call the parse() method; I pass in the String, and it returns a LocalDate object:

LocalDate someDate = LocalDate.parse( "2019-06-30" );

There are other lots of other methods you can use to create LocalDate objects, but this was all I needed to do.  Take a look at the API for other possible methods, like now() or of().

Converting back to a String

LocalDate provides a toString() method, which returns a String in the YYYY-MM-DD format:

String dateAsString = someDate.toString();

Of course, because Java will call toString() automatically when converting an object to a String, I can display the date with:

System.out.println( "The date is " + someDate );

LocalDate manipulation

If I want to get the day before the current date, I can use the minusDays() method:

LocalDate dayBefore = someDate.minusDays( 1 );

Note that LocalDate objects are immutable; once they’re set, you can’t change them, so the minusDays() method doesn’t change the original date, it returns a new LocalDate object with the new date.  As a result, if I wanted to change the someDate variable, I’d have to do:

someDate = someDate.minusDays( 1 );

If I want to change by other units, there’s also minusWeeks(), minusMonths(), and minusYears().  You can also use the minus() methods for more complicated manipulation, but I didn’t need to bother with that.  So anyways, here’s how I can get the date from the week before:

LocalDate weekBefore = someDate.minusWeeks( 1 );

Similarly, if I want to get the next day, I can use the plusDays() method:

LocalDate dayAfter = someDate.plusDays( 1 );

There are similar methods for plusWeeks(), plusMonths(), plusYears(), and plus().

Comparing LocalDates

LocalDate provides the standard comparison functions that we’re all used to: the equals() method checks if two dates are equal:

someDate.equals( dayBefore )

evaluates to false, and the compareTo() method compares two dates, returning an integer less than, equal to, or greater than zero:

someDate.compareTo( dayBefore )

evaluates to a value greater than 0.

For some reason, my brain has never been able to remember the order of compareTo(); does it compare the parameter to the object, or the object to the parameter?  I always have to try it out in test code, and I inevitably get it the wrong way! But, with LocalDates, there’s some nice comparison methods I can use so I don’t have to think about it!  If I want to see if a date is before, I can use the isBefore() method:

someDate.isBefore( dayBefore )

evaluates to false.  I can wrap my head around that: I just read the code and it makes sense — “is someDate before dayBefore?”

There’s also an isAfter() method:

someDate.isAfter( dayBefore )

evaluates to true.

There’s also an isEqual() method; you can use that, or equals().

I wish there was an isOnOrAfter() or isOnOrBefore() method, but there’s not; I just have to use compareTo() for that.

Other methods

LocalDate provides lots and lots of other methods, but I didn’t need to use them.  Take a look; if you’re wanting to do some simple date manipulation, there might be something there you want to use!

All the code

Here’s the program I used to test all the code in this post:

import java.time.LocalDate;

public class SimpleDateExample {
    public static void main( String[] args ) {
        LocalDate someDate = LocalDate.parse( "2019-06-30" );
        String dateAsString = someDate.toString();
        System.out.println( "dateAsString = " + dateAsString );
        System.out.println( "The date is " + someDate );

        LocalDate dayBefore = someDate.minusDays( 1 );
        System.out.println( "Day before: " + dayBefore );

        // someDate = someDate.minusDays( 1 );
        // System.out.println( "The date is " + someDate );

        LocalDate weekBefore = someDate.minusWeeks( 1 );
        System.out.println( "Week before: " + weekBefore );

        LocalDate dayAfter = someDate.plusDays( 1 );
        System.out.println( "Day after: " + dayAfter );

        System.out.println( "Using equals: " +
            someDate.equals( dayBefore ) );

        System.out.println( "Using compareTo with dayBefore: " +
            someDate.compareTo( dayBefore ) );

        System.out.println( "Using compareTo with dayAfter: " +
            someDate.compareTo( dayAfter ) );

        System.out.println( "Using isBefore: " +
            someDate.isBefore( dayBefore ) );

        System.out.println( "Using isAfter: " +
            someDate.isAfter( dayBefore ) );
    }
}

How to set up SQLite with JDBC in Eclipse on Windows

SQLite bannerI’m working on a little project written in Java, and I want to have a simple database in it.  I decided the easiest way to do it was with SQLite, but it’s been quite a while since I used SQLite in Java.  So, in this post, I’m recording steps on what I had to do to use SQLite with JDBC in Eclipse on Windows, and I also have some really simple sample code showing how to use it.

What’s SQLite?

According to the SQLite home page:

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.

OK, good enough for me.

Wait a minute, SQLite is a C language library — I want to use it in Java!

Luckily, somebody has created a JDBC driver wrapped around the C language library, so that we can use it in Java programs.  The code for the JDBC driver is available on GitHub at https://github.com/xerial/sqlite-jdbc, and there’s extensive documentation linked from that page.

Downloading the JDBC driver

You can get the JDBC driver from a page on BitBucket: https://bitbucket.org/xerial/sqlite-jdbc/downloads/.  At the time that I wrote this post, the latest version was 3.30.1 — download the file named sqlite-jdbc-3.30.1.jar, or a more recent version if there’s one available when you read this.

Installing the JDBC driver into an Eclipse project

OK, I’m going to create a new Eclipse Java project to contain some examples of using the JDBC driver, and then I’ll install the JDBC driver into that.

From the Eclipse menu, select File, then under that, select New, and then Java Project.  This is the same way you create any Java project; using the JDBC driver makes no difference in this step.  Give your project a name (I called mine jdbc-example), and select whatever options you want. I pretty much left mine at the default:

Create a Java Project window

Click Finish (or Next if you want to do additional configuration), and you’ll have a new empty Java project.  Here’s my project in the Eclipse Package Explorer:

New empty project in Package Explorer

Now, you’re going to want to put the JDBC driver that you downloaded somewhere that you can reference it.  To make things easy, I’m just going to put it in my project folder. Copy the Jar file into the top level of your project — I just used the File Explorer to drag it from my Downloads folder and dropped it on the jdbc-example folder in the Eclipse Package Explorer.  When I did that, Eclipse gave me the following window:

Drag-and-drop JAR file

I want to make a copy of the Jar file, rather than linking to the file in my Downloads folder, so I left “Copy files” selected and pressed OK.  When I did that, I can see that a copy of the Jar file is now in my project:

Package Explorer with Jar file

Note that I could put it anywhere; I can even reference it in my Downloads folder, but I like to keep my project files all together.  Anyways, the next step is to tell Eclipse that I want to add that Jar file to my project’s Java Build Path. Open the Project Properties by right-clicking on the jdbc-example project in the Package Explorer, then selecting Properties at the bottom of the pop-up menu (or alternatively, just click once on the jdbc-example project, then press Alt-Enter).  You’ll now get the project’s Properties window, and it will look something like this (but without the red ellipse!):

Initial project properties window

I want to change the Java Build Path.  Click on Java Build Path on the left-hand side of the window (circled in red), and your window will now look like something like this (again, without the red ellipse):

Properties window: Java Build Path

I want to change the Libraries, so on the right side of the window, select the Libraries pane (circled in red).  Then, you’ll get:

Java build path - Libraries pane

As you can probably guess, you’ll now want to click on the “Add JARs…” button.  You’ll get the following pop-up window, listing the projects in your Eclipse workspace:

JAR selection - collapsed

Expand your project:

JAR selection - expanded

Select sqlite-jdbc-3.30.1.jar, and press OK.  You’ll now see that file show up in the Libraries pane (funky hand-drawn arrows added by me!):

Jar added to build path

And you’re now good to go!  Click the “Apply and Close” button, and you’re all set to use JDBC in your Java project in Eclipse!

Is there any SQLite-JDBC API documentation?

Yup, there sure is.  I found it at https://www.javadoc.io/doc/org.xerial/sqlite-jdbc/3.30.1/index.html.

Some sample code

OK, you’re probably thinking, that’s great, but how do I use it?  I’ve got some sample code and explanations below, but you can also check out the examples on the JDBC driver’s GitHub page and the official “JDBC Basics” Java Tutorial from Oracle.

Creating a database

The first thing you’re going to want to do is create the database.  You might already have one that you’re trying to access, but if you don’t, here’s some code to do it for you.

Actually, all we’re really going to do is to try to connect to a database.  If it doesn’t already exist, the SQLite JDBC driver will create one for us.

In JDBC, a database is represented by a DataSource, so the first thing we need to do is to create a DataSource.  Well, actually, a DataSource is just an interface, so we need to create an object that implements that interface.  The driver supplies a class called SQLiteDataSource that we’ll use. Note that to use it, you’ll need to import it from the org.sqlite.SQLiteDataSource package; you should be able to get Eclipse to do that for you when it gives you an error about not being able to resolve SQLiteDataSource to a type.  Anyways, here’s some code that creates the object:

SQLiteDataSource ds = new SQLiteDataSource();

We’ve now got a DataSource object, but it doesn’t know where the database is!  We can tell it that by using the setUrl method:

ds.setUrl("jdbc:sqlite:test.db");

So, this tells the driver we’re going to connect to an SQLite database in a file called test.db in the current directory.  If you want to specify a complete pathname, you’d do something like:

ds.setUrl("jdbc:sqlite:C:/users/shane/mydatabase.db");

Note that you’d use forward slashes, not backslashes as you might expect since we’re doing this on Windows!

Once we’ve got the DataSource all set up, we need to tell it to create the database.  Actually, what we’re going to do is try to connect to the database; if it doesn’t exist, the JDBC driver will create it for us.  So, we need to create a Connection object. We can do that with:

Connection conn = ds.getConnection();

And that’s it!

OK, I used a bit more code.  Because setting up a DataSource might throw an exception, I want to wrap that in a try-catch block.  And because a Connection can throw an SQLException when I try to get the connection, I’ll do something similar.  Note, though, that a Connection implements the AutoCloseable interface, so I can use the try-with-resources statement to make my code a little cleaner.  So, here’s some example code that will create an SQLite database in a file called test.db:

import java.sql.Connection;
import java.sql.SQLException;

import org.sqlite.SQLiteDataSource;

public class CreateDbExample {

    public static void main(String[] args) {
        SQLiteDataSource ds = null;

        try {
            ds = new SQLiteDataSource();
            ds.setUrl("jdbc:sqlite:test.db");
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(0);
        }
        System.out.println( "Opened database successfully" );

        try ( Connection conn = ds.getConnection() ) {
        } catch ( SQLException e ) {
            e.printStackTrace();
            System.exit( 0 );
        }

        System.out.println( "Created database successfully" );
    }

}

A plea: this exception-catching code is horrendous.  Although it’s fine for an example, don’t do it this way in real code.  Think about what you’re doing, and properly handle and clean up an exception!

When you run this program, a file named test.db will be created in your project folder.  If you refresh Eclipse’s Package Explorer, you’ll see it show up:

Package explorer with DB file

Creating a database with a DriverManager

The old way of using JDBC was to use a DriverManager to create the connection.  The code is simpler, but Oracle recommends using a DataSource for creating connections.  But, if you want to do it the old way, here’s sample code:

import java.sql.Connection;
import java.sql.DriverManager;

public class CreateDbWithDriverManagerExample {

    public static void main(String[] args) {
        try (Connection conn =
                DriverManager.getConnection("jdbc:sqlite:test.db");
            ) {
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }

        System.out.println("Opened database successfully");
    }

}

Creating a table

Creating a table is a nice example, because you will use the same concepts to perform many other database operations, other than reading from the database.  Anyways, you start by creating a DataSource object and a Connection object. Once you’ve got a Connection object, you can create a Statement object, and you’ll use that Statement object to execute the command.  To create the Statement object from a Connection object named conn, do the following:

Statement stmt = conn.createStatement();

Again, a Statement implements AutoCloseable, so you can use a try-with-resources statement to simplify your code (see the full example code below).

Once you’ve got a Statement, there are three methods that you can call to execute database commands:

  • executeUpdate(), which is used to update the database.  It returns the number of rows in the database that were affected by the Statement.  This is what you’ll use when you execute a CREATE, INSERT, DELETE, or UPDATE statement.
  • executeQuery(), which is used when you are making a query against the database.  It returns a ResultSet object, which contains a number of results. This is what you’ll use when you execute a SELECT statement.
  • execute(), which is used when you are expecting one or more ResultSet objects to be returned.  I won’t be using this in this post, because I’ll only return a single ResultSet object — ResultSet objects can contain more than one result.

OK, so if we’re going to create a table, we’ll want to use executeUpdate.  Here’s the SQL code to create a table I’ll use in these examples:

CREATE TABLE IF NOT EXISTS test
  ( ID INTEGER PRIMARY KEY, 
    NAME TEXT NOT NULL );

To run the command, pass it into executeUpdate() as a String.  For my example code, I’m going to create a String object containing the command, then pass that String in.  I could just pass a String constant in, but I thought my code was a little more readable this way.

String query = "CREATE TABLE IF NOT EXISTS test ( " +
                 "ID INTEGER PRIMARY KEY, " +
                 "NAME TEXT NOT NULL )";

Statement stmt = conn.createStatement();
int rv = stmt.executeUpdate( query );

Note: rv is short for return value.  Here’s my full code example:

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import org.sqlite.SQLiteDataSource;

public class CreateTableExample {

    public static void main(String[] args) {
        SQLiteDataSource ds = null;

        try {
            ds = new SQLiteDataSource();
            ds.setUrl("jdbc:sqlite:test.db");
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(0);
        }
        System.out.println( "Opened database successfully" );

        String query = "CREATE TABLE IF NOT EXISTS test ( " +
                         "ID INTEGER PRIMARY KEY, " +
                         "NAME TEXT NOT NULL )";

        try ( Connection conn = ds.getConnection();
              Statement stmt = conn.createStatement(); ) {
            int rv = stmt.executeUpdate( query );
            System.out.println( "executeUpdate() returned " + rv );
        } catch ( SQLException e ) {
            e.printStackTrace();
            System.exit( 0 );
        }
        System.out.println( "Created database successfully" );
    }

}

When you run it, it creates the table.  Note that rv will have the value 0, because no rows were updated.

Inserting rows into the table

Inserting rows into the table is basically the exact same code, you just change the query String:

String query = "INSERT INTO test ( NAME ) VALUES ( 'Shane' )";

When you call executeUpdate(), it will return the value 1, because you have updated 1 row.

Here’s a snippet of my example code.  I’m actually inserting two rows, one at a time.  In my example, you can see they are both wrapped inside the same try-with-resources statement:

System.out.println( "Attempting to insert two rows into test table" );

String query1 = "INSERT INTO test ( NAME ) VALUES ( 'Shane' )";
String query2 = "INSERT INTO test ( NAME ) VALUES ( 'Sharon' )";

try ( Connection conn = ds.getConnection();
      Statement stmt = conn.createStatement(); ) {
    int rv = stmt.executeUpdate( query1 );
    System.out.println( "1st executeUpdate() returned " + rv );

    rv = stmt.executeUpdate( query2 );
    System.out.println( "2nd executeUpdate() returned " + rv );
} catch ( SQLException e ) {
    e.printStackTrace();
    System.exit( 0 );
}

Updating and deleting rows

Once again, when updating and deleting rows, you use the same code, just change the query string.  Examples:

String query = "UPDATE test SET NAME = 'Poopsie'" +
               " WHERE NAME = 'Sharon'";

and

String query = "DELETE FROM test WHERE NAME = 'Shane'";

Deleting a table

Deleting a table works the same way, just a different query String:

String query = "DROP TABLE IF EXISTS test";

Querying a table

To query a table, create a query String, but pass it into executeQuery() rather than executeUpdate():

String query = "SELECT * FROM test";

ResultSet rs = stmt.executeQuery(query);

A ResultSet object is returned.  This contains a number of results.  See the Java Tutorial “Retrieving and Modifying Values from Result Setsfor details, but here’s a simple case where I loop through all the results that come back in the ResultSet and display them:

while ( rs.next() ) {
    int id = rs.getInt( "ID" );
    String name = rs.getString( "NAME" );

    System.out.println( "Result: ID = " + id + ", NAME = " + name );
}

The next() method returns true if there are more results in the ResultSet to be processed.  To get the actual values from the result, you use the various get*() methods, depending on the type of the row.  In my example table, the ID field is an INTEGER, and the NAME field is TEXT, so I use getInt() for the ID and getString() for the NAME.

Here’s my full example code:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.sqlite.SQLiteDataSource;

public class SelectRowsExample {

    public static void main(String[] args) {
        SQLiteDataSource ds = null;

        try {
            ds = new SQLiteDataSource();
            ds.setUrl("jdbc:sqlite:test.db");
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(0);
        }

        System.out.println( "Opened database successfully" );

        System.out.println( "Selecting all rows from test table" );
        String query = "SELECT * FROM test";

        try ( Connection conn = ds.getConnection();
              Statement stmt = conn.createStatement(); ) {
            ResultSet rs = stmt.executeQuery(query);

            while ( rs.next() ) {
                int id = rs.getInt( "ID" );
                String name = rs.getString( "NAME" );

                System.out.println( "Result: ID = " + id +
                    ", NAME = " + name );
            }
        } catch ( SQLException e ) {
            e.printStackTrace();
            System.exit( 0 );
        }
    }

}

Final words

So, there’s the basics of how you set up the SQLite JDBC driver, and some simple examples of using it.  Refer to the Oracle documentation for more detailed examples, but these examples should get you through the basics.  Have fun!

Where can I get a copy of the sample code?

I’m glad you asked.  I put a copy up on BitBucket.  You can find it at https://bitbucket.org/shaneroo/jdbc-example.