title: Connecting MySQL from JSP
body: <p>I just set foot on JSP. I started writing simple programs to display dates, system info. Then I tried to connect a <code>MySQL database</code> I have a free hosting account, but I am not able to connect to MySQL database. Here is my code:</p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt; 
  &lt;%@ page import="java.io.*" %&gt; 
  &lt;html&gt; 
  &lt;head&gt; 
  &lt;title&gt;Connection with mysql database&lt;/title&gt;
  &lt;/head&gt; 
  &lt;body&gt;
  &lt;h1&gt;Connection status&lt;/h1&gt;
  &lt;% 
  try {
      String connectionURL = "jdbc:mysql://mysql2.000webhost.com/a3932573_product";
      Connection connection = null; 
      Class.forName("com.mysql.jdbc.Driver").newInstance(); 
      connection = DriverManager.getConnection(connectionURL, "a3932573_dibya", "******");
      if(!connection.isClosed())
           out.println("Successfully connected to " + "MySQL server using TCP/IP...");
      connection.close();
  }catch(Exception ex){
      out.println("Unable to connect to database.");
  }
  %&gt;
  &lt;/font&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>I am getting Message as <strong>Connection Status unable to connect to database</strong>. I have tested this connection using <code>PHP</code> using the same username, password and database name. Where am I making mistake?</p>