title: How to check if a particular database in mysql already exists using java
body: <p>I am new in JDBC and I wanted to find out if there is a way to check if a particular database already exists in MySQL.</p>
  <p>Let's say I wanted to create a database named students, if the students database is already created in MySQL an error message in eclipse would state that this students database already exists. However what I wanted to do is to create a boolean method to check if students database already exists. If it exists then boolean method would return false otherwise its true then I can create students database.
  How do I do these in Java? Are there any methods in JDBC that does this or do I need to code it from scratch?</p>
  <h3>EDIT 2</h3>
  <p>I followed mguymons suggestion and this is what I came up</p>
  <pre><code>public boolean checkDBExists(String dbName){
  
      try {
          Class.forName(JDBCDriver); //Register JDBC Driver
          
          System.out.println(&quot;Creating a connection...&quot;);
          conn = DriverManager.getConnection(DBURL, USER, PASS); //Open a connection
      
          ResultSet resultSet = conn.getMetaData().getCatalogs();
          
          while (resultSet.next()) {
          
            String databaseName = resultSet.getString(1);
              if(databaseName.equals(dbName)){
                  return true;
              }
          }
          resultSet.close();
  
      }
      catch(Exception e){
          e.printStackTrace();
      }
      
      return false;
  }
  </code></pre>