Since \( a^2x + 2 \) and \( x^2 - bx + a \) are all continuous for any \( a \) and \( b \), we only need to check continuity at \( x = 3 \).
We have \( f(3) = 5 \), \( \displaystyle \lim_{x \to 3^+} ~ f(x) = \lim_{x \to 3^+} ~ (a^2x + 2) = a^2(3) + 2 = 3a^2 + 2 \) and \( \displaystyle \lim_{x \to 3^-} ~ f(x) = \lim_{x \to 3^-} ~ (x^2 - bx + a) = (3)^2 - 3b + a = a - 3b + 9 \), so \( f \) is continuous if and only if \( 3a^2 + 2 = 5 ~~ (1) \) and \( a - 3b + 9 = 5 ~~ (2) \).
From \( (1) \), \( 3a^2 = 3 \) and so \( a = \pm 1 \).
From \( (2) \), \( a - 3b + 9 = 5 \).
If \( a = 1 \), then \( 3b = 5 \) and \( b = \frac{5}{3} \).
If \( a = -1 \), then \( 3b = 3 \) and \( b = 1 \).
Therefore, the solutions for \( a \) and \( b \) are \( a = 1, b = \frac{5}{3} \) or \( a = -1, b = 1 \).