title: My database class is too big/poor coding, how can I make this better?
body: <p>I'm developing a GWT program, connected to a MySQL database. Let me preface by saying I'm fairly far into this, and I don't know struts, or hibernate or the like. My database calls have become large and I'd like to change that to a better practice. Things have seem to have gotten convoluted. </p>
  
  <p>In my <code>databaseServiceImpl</code> class I have a series of methods that each do one thing (add client, delete client, add product, add order, etc) which means I now have 50+ methods, all somewhat similar but different results or objects used. 
  here is an example of a method from this class </p>
  
  <pre><code>    @Override
  public int addClient(Client client) throws DatabaseException {
      Connection con = connect();
      PreparedStatement ps = null;
      ResultSet rs = null;
      int clientID = 0;
      // insert client into client table
      try {
          String query = "INSERT INTO clients (clientID, name, description, notes, address, contactName, contactNumber) VALUES (" + "NULL,'"
                  + client.getClientName() + "','" + client.getDescription() + "','" + client.getNotes() + "','" + client.getAddress() + "','"
                  + client.getContactName() + "','" + client.getContactNumber() + "')";
          ps = con.prepareStatement(query);
          System.out.println("addClient: " + ps.toString());
          clientID = ps.executeUpdate(query, ps.RETURN_GENERATED_KEYS);
          con.commit();
          System.out.println("Transactions are being committed.");
          while (rs.next()) {
              clientID = rs.getInt(1);
          }
      } catch (SQLException e) {
          try {
              con.rollback();
              System.out.println("Transactions are being rolled back.");
          } catch (SQLException e1) {
              e1.printStackTrace();
          }
          throw new DatabaseException(e);
      } finally {
          close(rs, ps, con);
      }
      return clientID;
  }
  </code></pre>
  
  <p>Ok, maybe this wouldn't be so bad, but every time I call a method from the dataservice (even for something small) I end up needing this,</p>
  
  <pre><code>Ioma.dataservice.addClient(name.getText(), desc.getText(), notes.getText(), address.getText(), contactName.getText(),
  phone.getText(), new AsyncCallback&lt;Integer&gt;() {
  @Override
  public void onFailure(Throwable caught) {
      new GuiErrorDialog("Add Client", caught);
  }
  @Override
  public void onSuccess(Integer result) {
      Window.alert("Client " + name.getText() + " added");
      }
  });
  </code></pre>
  
  <p>Which seems excessive to me for simple queries and results. I understand that database calls in GWT are asynchronous calls but I can't help but feel I'm following incorrect or poor coding practices. What can I do to make this better? </p>