stmt.executeQuery("select * from user where username = " + name);
This code is executed it will trigger the error.
The reason is: when pieced sql statement to character type data is not enclosed in quotation marks
Change to correct the following statement
stmt.executeQuery("select * from user where username = '" + name + "'");