title: MYSQL One connection for one class
body: <p>I am learning about MySQL database and I cannot quite understand one concept. Lets say there are two methods in the same class as the one shown below. Now, do i have to use Connection connect = dbConnection.getDBConnection(); in each method or is there a different way to declare one connection and use it across multiple methods?:</p>
  
  <pre><code>private void setUpdateButton(ActionEvent event) {
      try{
          Connection connect = dbConnection.getDBConnection();
          Statement stmt = connect.createStatement();
  
  
          if(txtID.getText().trim().isEmpty()||txtFirstName.getText().trim().isEmpty() || txtSecondName.getText().trim().isEmpty() ||
                  txtGender.getText().trim().isEmpty() || txtAge.getText().trim().isEmpty() || txtHomeAddress.getText().trim().isEmpty() || txtPhoneNumber.getText().trim().isEmpty()) {
              showAlert("Invalid Input!", "All fields need to be populated before updating.");
          }else {
                 String sqlQuery ="update student_information set Age ='"+Integer.parseInt(txtAge.getText())+"',Name ='"+txtFirstName.getText()+"',Surename='"+txtSecondName.getText()
              +"',Gender='"+txtGender.getText()+"',Address='"+txtHomeAddress.getText()+"',PhoneNumber='"+txtPhoneNumber.getText()+"'where ID="+Integer.parseInt(txtID.getText());
                 stmt.executeLargeUpdate(sqlQuery);
                 setTxtArea();
                 showConfAlert("Update Completed!", "Record has been updated!");
  </code></pre>