Servlet + MySql -- UPDATE query will not work

WHY WON"T THIS WORK...
I need  a fresh view, i'm not getting anywhere anymore

public class DBupdate extends HttpServlet {
        
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response)
                       throws ServletException, IOException {
               response.setContentType("text/html");
               PrintWriter out = response.getWriter();
               String driver = "com.mysql.jdbc.Driver";
               String url = "jdbc:mysql://localhost:3306/some-db";
               String username = "some-user";
               String password = "some-password";
               String query = "UPDATE users SET users.changed_pass = \"1\" WHERE users.user_name = \"another-user\";";                       showTable(driver, url, username, password, query, out);
              response.sendRedirect("/core/index2.jsp");
              }

        public void showTable(String driver, String url,
                          String username, String password,
                          String query, PrintWriter out) {
    try {
            // Load database driver if it's not already loaded.
            Class.forName(driver);
            // Establish network connection to database.
            Connection connection = DriverManager.getConnection(url, username, password);
            Statement statement = connection.createStatement();
                statement.executeQuery(query);
                query = "SELECT * FROM users;";
            ResultSet resultSet = statement.executeQuery(query);
            // Print results by steping through each row in the result set.
          while(resultSet.next()) {
                if (resultSet.getString(1).equals("0")) {
                      firstVisit = "true";
                } else {
                      firstVisit = "false";
                }
          }      
            //out.print("this is the resultSet value = " + resultSet.getString(1) );
            connection.close();
    }
    catch(ClassNotFoundException cnfe) {
          System.err.println("Error loading driver: " + cnfe);
    }
    catch(SQLException sqle) {
            System.err.println("Error connecting: " + sqle);
    } catch(Exception ex) {
            System.err.println("Error with input: " + ex);
    }
   
  }

  private static void showResults(ResultSet results)
      throws SQLException {
    while(results.next()) {
      System.out.print(results.getString(1) + " ");
    }
    System.out.println();
  }

  private static void printUsage() {
    System.out.println("Usage: PreparedStatements host " +
                       "dbName username password " +
                       "vendor [print].");
  }
}            
benk-master-flashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>statement.executeQuery(query);

should be

statement.executeUpdate(query);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bobbit31Commented:
are you getting a compile error? or is it just not updating?

i don't see any declaration for the variable firstVisit.
0
CEHJCommented:
... but unless your db is set to read uncommitted, you may not see the change as the statement does not get closed before the select
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

benk-master-flashAuthor Commented:
OK let me try this...
0
CEHJCommented:
You shouldn't need terminating semicolons and it would probably be better to use single quotes for character columns in statements
0
benk-master-flashAuthor Commented:
I should have posted the question an hour ago...
oh well. good work, nothing link a simple answer
thanks!
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.