@Test
  public void testURIDatabaseName() throws Exception{

    String  jdbcUri  = miniHS2.getJdbcURL().substring(0, miniHS2.getJdbcURL().indexOf("default"));

    Connection conn= getConnection(jdbcUri+"default", System.getProperty("user.name"),"bar");
    String dbName="test_connection_non_default_db";
    String tableInNonDefaultSchema="table_in_non_default_schema";
    Statement stmt = conn.createStatement();
    stmt.execute("create database  if not exists "+dbName);
    stmt.close();
    conn.close();

    conn = getConnection(jdbcUri+dbName,System.getProperty("user.name"),"bar");
    stmt = conn .createStatement();
    boolean expected = stmt.execute(" create table "+tableInNonDefaultSchema +" (x int)");
    stmt.close();
    conn .close();

    conn  = getConnection(jdbcUri+dbName,System.getProperty("user.name"),"bar");
    stmt = conn .createStatement();
    ResultSet res = stmt.executeQuery("show tables");
    boolean testTableExists = false;
    while (res.next()) {
      assertNotNull("table name is null in result set", res.getString(1));
      if (tableInNonDefaultSchema.equalsIgnoreCase(res.getString(1))) {
        testTableExists = true;
      }
    }
    assertTrue("table name  "+tableInNonDefaultSchema
        + "   found in SHOW TABLES result set", testTableExists);
    stmt.close();
    conn .close();

    conn  = getConnection(jdbcUri+"default",System.getProperty("user.name"),"bar");
    stmt = conn .createStatement();
    res = stmt.executeQuery("show tables");
    testTableExists = false;
    while (res.next()) {
      assertNotNull("table name is null in result set", res.getString(1));
      if (tableInNonDefaultSchema.equalsIgnoreCase(res.getString(1))) {
        testTableExists = true;
      }
    }

    assertFalse("table name "+tableInNonDefaultSchema
        + "  NOT  found in SHOW TABLES result set", testTableExists);
    stmt.close();
    conn .close();

    conn  = getConnection(jdbcUri+dbName,System.getProperty("user.name"),"bar");
    stmt = conn .createStatement();
    stmt.execute("set hive.support.concurrency = false");
    res = stmt.executeQuery("show tables");

    stmt.execute(" drop table if exists table_in_non_default_schema");
    expected = stmt.execute("DROP DATABASE "+ dbName);
    stmt.close();
    conn.close();

    conn  = getConnection(jdbcUri+"default",System.getProperty("user.name"),"bar");
    stmt = conn .createStatement();
    res = stmt.executeQuery("show tables");
    testTableExists = false;
    while (res.next()) {
      assertNotNull("table name is null in result set", res.getString(1));
      if (tableInNonDefaultSchema.equalsIgnoreCase(res.getString(1))) {
        testTableExists = true;
      }
    }

    // test URI with no dbName
    conn  = getConnection(jdbcUri, System.getProperty("user.name"),"bar");
    verifyCurrentDB("default", conn);
    conn.close();

    conn  = getConnection(jdbcUri + ";", System.getProperty("user.name"),"bar");
    verifyCurrentDB("default", conn);
    conn.close();

    conn  = getConnection(jdbcUri + ";/foo=bar;foo1=bar1", System.getProperty("user.name"),"bar");
    verifyCurrentDB("default", conn);
    conn.close();
  }
This test is to connect to any database without using the command "Use <<DB>>"
 1) connect to default database.
 2) Create a new DB test_default.
 3) Connect to test_default database.
 4) Connect and create table under test_default_test.
 5) Connect and display all tables.
 6) Connect to default database and shouldn't find table test_default_test.
 7) Connect and drop test_default_test.
 8) drop test_default database.
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java