samedi 25 juin 2016

'Operation not available after Result Set closed'


I've looked on here for reasons why it would occur and the only thing that I could see would cause that would be because of an open connection. In my code, I close a connection and register a new one to reopen.

try{

       //Registration of driver, connector
        String myDriver = "com.mysql.jdbc.Driver";
        String myURL = "jdbc:mysql://localhost:3306/maintenance";
        Class.forName(myDriver);
        Connection connection = DriverManager.getConnection(myURL, "admin", "");


        //Call MySQL for table names of users
        String query = "SELECT users FROM goods";

        Statement st = connection.createStatement();


        ResultSet res = st.executeQuery(query);

            while (res.next()) {

                String name = res.getString("users");


                if(name.equals(username)){
                    connection.close();
                    res.close();
                          try{
                         Connection connection2;
                         connection2 = DriverManager.getConnection("jdbc:mysql://localhost:3306/maintenance", "admin", "");
                         query = "SELECT idkeys FROM goods";
                         Statement st2;
                         st2 = connection2.createStatement();
                         ResultSet res2;
                         res2 = st2.executeQuery(query);
                         String myDriver2 = "com.mysql.jdbc.Driver";
                         Class.forName(myDriver2);
                         connection2 = DriverManager.getConnection("jdbc:mysql://localhost:3306/maintenance", "admin", "");
                         while (res2.next()) {

                             keyed = res2.getObject("idkeys");

                             if (keyed.equals(sanitizedPass)){
                                 checked = true;
                                 connection2.close();
                                 res2.close();

                             }
                         } 
                    } catch (Exception e2){
                        System.err.println(e2.getMessage());

                    }

                }

  }
  //Close connections  
  if (!checked){
  res.close();
  connection.close();
  }
    }
    catch(Exception e)
    {
        System.err.println(e.getMessage());  
   }

    return checked;

In my code, at least as far as I know, no such thing happens. Why would it still get thrown?


Aucun commentaire:

Enregistrer un commentaire