The New South Wales Nationals have held onto the seat of Upper Hunter in a by-election which has left the Labor party "shell-shocked".