Java JDBC Database Metadata createHsqlPlSchemaIfNecessary(Connection con)

Here you can find the source of createHsqlPlSchemaIfNecessary(Connection con)

Description

Creates a schema called "pl" in the given HSQLDB connection.

License

Open Source License

Declaration

private static void createHsqlPlSchemaIfNecessary(Connection con) throws SQLException 

Method Source Code

//package com.java2s;
/*// w ww .ja va  2s.c o  m
 * Copyright (c) 2008, SQL Power Group Inc.
 *
 * This file is part of DQguru
 *
 * DQguru is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * DQguru is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**
     * Creates a schema called "pl" in the given HSQLDB connection.
     */
    private static void createHsqlPlSchemaIfNecessary(Connection con) throws SQLException {
        DatabaseMetaData dbmd = con.getMetaData();
        ResultSet rs = dbmd.getSchemas();
        boolean foundPlSchema = false;
        while (rs.next()) {
            if ("pl".equalsIgnoreCase(rs.getString("TABLE_SCHEM"))) {
                foundPlSchema = true;
            }
        }
        rs.close();
        if (!foundPlSchema) {
            Statement stmt = con.createStatement();
            stmt.executeUpdate("CREATE SCHEMA pl AUTHORIZATION DBA");
            stmt.close();
        }
    }
}

Related

  1. adjustIdentifierCase(String identifier, Connection conn)
  2. getAllTables(Connection connection)
  3. getAllTables(Connection connection)
  4. getCatalogs(Connection c)
  5. getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)