title: Why i can't connect to mysql database in java?
body: <p>I found this code in a tutorial but it isn't working when I debug it try the connection and then it isn't throw exception only go to the finally block without do any line of code under the DriverManager.getConnection().
  Why? Anyone has an idea?</p>
  
  <pre><code>            Connection con = null;
              Statement st = null;
              ResultSet rs = null;
  
              String url = "jdbc:mysql://host/databasename";
              String user = "user";
              String password = "pass";
  
  
              try {
                  Class.forName("com.mysql.jdbc.Driver");
              } catch (ClassNotFoundException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
  
              try {
                  con = (Connection) DriverManager.getConnection(url, user, password);
                  st = (Statement) con.createStatement();
                  rs = st.executeQuery("SELECT * FROM Message");
  
                  if (rs.next()) {
                      System.out.println(rs.getString(1));
                  }
  
              } catch (SQLException ex) {
                  Logger lgr = Logger.getLogger(Version.class.getName());
                  lgr.log(Level.SEVERE, ex.getMessage(), ex);
  
              } catch (java.sql.SQLException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } 
              catch (Exception e) {
                  // TODO: handle exception
                  e.printStackTrace();
              }
              finally {
                  try {
                      if (rs != null) {
                          rs.close();
                      }
                      if (st != null) {
                          st.close();
                      }
                      if (con != null) {
                          con.close();
                      }
  
                  } catch (SQLException ex) {
                      Logger lgr = Logger.getLogger(Version.class.getName());
                      lgr.log(Level.WARNING, ex.getMessage(), ex);
                  } catch (java.sql.SQLException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
  </code></pre>
  
  <p>Logcat write this:
  <a href="http://postimg.org/image/mghkuaoz7/" rel="nofollow">Logcat Message</a></p>