title: How to check if a DataBase exist or not after the connection is made JAVA
body: <p>I have a big question...
  I have a database java program creation.</p>
  
  <p>I want to know if the database exists or not, and the if exists just connect, if not to create it.</p>
  
  <p>I tried this one:</p>
  
  <pre><code>if (dbName.exists() == false) {}
  </code></pre>
  
  <p>THIS IS ALL THE CODE... </p>
  
  <pre><code>Class.forName("com.mysql.jdbc.Driver");
  System.out.println("MySQL JDBC driver loaded ok.");
  </code></pre>
  
  <p>THIS IS A BACKUP CODE FOR IT, JUST TO WORK FOR NOW....
  PARTIAL CODE THAT WORKS !</p>
  
  <pre><code>conn = DriverManager.getConnection(DBurl + url
  + "?createDatabaseIfNotExist=true&amp;amp; + "
  + "useUnicode=true&amp;amp;characterEncoding=utf-8&amp;user="
  + userName + "&amp;amp;&amp;password=" + password);
  
  
  System.out.println("Connected to database ");           
  System.out.println("Connected to the database " + url);
  </code></pre>
  
  <p>BUT I WANT SOMETHING LIKE:</p>
  
  <pre><code>FILE dbName = new FILE (url);
  Statement stmt = new Statement;
  
  if (dbName.exists() == true)
     System.out.println("Database exists ! Connecting ... ");
  else {
     String sql = "CREATE DATABASE "+url;
     stmt.executeUpdate (sql);
  }
  </code></pre>
  
  <p>I don't want to put the url with the password and username in the same place... because they are provided from an external part, but that is allready implemented and working.</p>
  
  <p>So I want to rip in 2 peaces, 1 Connect "jdbc:mysql://localhost:3306/"; WITHOUT URL which is the database NAME ... 
  AND THEN IF A DATABASE DOES NOT EXISTS THERE WITH THAT NAME JUST CREATE ON.</p>
  
  <p>It is not working.... not entering in the <code>else</code> more, and says that Exeption Database already exists.</p>
  
  <p>Thanks you very much.</p>