Here you can find the source of getQualifiedTableName(DatabaseMetaData dbmd, String catalog, String schema, String table, boolean useQuotes)
Parameter | Description |
---|---|
dbmd | DatabaseMetaData |
catalog | String |
schema | String |
table | String |
useQuotes | boolean |
Parameter | Description |
---|---|
SQLException | an exception |
public static String getQualifiedTableName(DatabaseMetaData dbmd, String catalog, String schema, String table, boolean useQuotes) throws SQLException
//package com.java2s; /*//from ww w. jav a 2s.co m * Copyright (c) 2008-2011 Simon Ritchie. * All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see http://www.gnu.org/licenses/>. */ import java.sql.*; public class Main { /** * Return a fully qualified table name. This method examines the DatabaseMetaData to * determine whether catalog and schema should be included in the qualified table name. * If quotes are required, the appropriate quote characters for the database will be * used to support the name. * * @param dbmd DatabaseMetaData * @param catalog String * @param schema String * @param table String * @param useQuotes boolean * @return The qualified table name. * @throws SQLException */ public static String getQualifiedTableName(DatabaseMetaData dbmd, String catalog, String schema, String table, boolean useQuotes) throws SQLException { boolean catalogSupported = dbmd .supportsCatalogsInTableDefinitions(); boolean schemaSupported = dbmd.supportsSchemasInTableDefinitions(); String quote = dbmd.getIdentifierQuoteString(); String separator = dbmd.getCatalogSeparator(); if (separator == null || separator.trim().length() == 0) { separator = "."; } StringBuilder sb = new StringBuilder(); if (catalogSupported && catalog != null) { if (useQuotes) { sb.append(quote); } sb.append(catalog); if (useQuotes) { sb.append(quote); } sb.append(separator); } if (schemaSupported && schema != null) { if (useQuotes) { sb.append(quote); } sb.append(schema); if (useQuotes) { sb.append(quote); } sb.append(separator); } if (useQuotes) { sb.append(quote); } sb.append(table); if (useQuotes) { sb.append(quote); } return sb.toString(); } }