i was facing the same issue and here is what i have done and this works fine with me i have installed both java version 8 and 17
and in system variable i added one variable
JAVA_HOME
with value pointing to the java i want to use let's say java 8 like this
and in the path i have removed any older java bin paths there and added new one with value
%JAVA_HOME%\bin
but make sure to make it the first entry in path also when you want to change the java version you will just need to change the path for the JAVA_HOME variable i can recommend you also to create executable bat file to change the JAVA_HOME path if you do this a lot