title: How to use the mysql connection on multiple classes?
body: <p>I have some issues with the conection between java application and mysql.<br>
  This is my file(this file work very well): </p>
  
  <pre><code>import java.sql.*;
  
  import javax.swing.JFrame;
  
  public class MysqlConnect{
  
  public static void main(String[] args) throws SQLException {
  
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "jdbctutorial";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "birthday"; 
      String password = "123456";
      try {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url+dbName,userName,password);
          System.out.println("Connected to the database");
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  
  }
  }
  </code></pre>
  
  <p>Is possible "to separate" the main and mysql connection ??
  My idea is something like that :I have the MysqlConnection file and another GUI file.
  In the GUi file I have a button (ADD) and whenever I click this button some datas will be stored to database .My problem is that I don't know how run the query ,because I need the Statement variable ,Connection variable,etc..What I suppose to do ?To do the mysqlConnection and GUI in the same file ?Another idea of mine is to do an object of type MysqlConnection and work with that object.And here is the problem :If I remove the <code>(public void main .....)</code> i have an error at try and catch.</p>
  
  <p>Sorry if my english is bad but I hope i make myself clear . 
  Thanks in advance .        </p>