title: Apache Tomcat use XAMPP MySQL Database
body: <p>I have installed Tomcat 6 and apache XAMPP on MAC OS. XAMPP includes MySQL.</p>
  
  <p>I turn on TOMCAT and XAMPP.</p>
  
  <p>Then i try to connect with JDBC to MySQL.</p>
  
  <pre><code>public class main {
  
      public static void main(String[] args) {
  
          Connection conn = null;
          try
          {
              String userName = "root";
              String password = "";
              //&lt;facility&gt; is the name of the database i created
              String url = "jdbc:mysql://localhost/facility"; 
              Class.forName ("com.mysql.jdbc.Driver").newInstance ();
              conn = DriverManager.getConnection (url, userName, password);
              System.out.println ("Database connection established");
          }
          catch (Exception e)
          {
              System.out.println ("Cannot connect to database server");
          }
  
          finally
          {
              if (conn != null)
              {
                  try
                  {
                      conn.close ();
                      System.out.println ("Database connection terminated");
                  }
                  catch (Exception e) { /* ignore close errors */ }
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>Well it gives me back "Cannot connect to database server".</p>